public void remapGuids(ref Dictionary <string, string> guidMap)
        {
            if (!guidMap.ContainsKey(pA_guid) || !guidMap.ContainsKey(pB_guid))
            {
                return;
            }

            string old_pA_guid_key = ArchimatixUtils.guidToKey(pA_guid);
            string old_pB_guid_key = ArchimatixUtils.guidToKey(pB_guid);

            string new_pA_guid_key = ArchimatixUtils.guidToKey(guidMap[pA_guid]);
            string new_pB_guid_key = ArchimatixUtils.guidToKey(guidMap[pB_guid]);

            //Debug.Log("+++ remapGuids pA_guid: " + old_pA_guid_key + "==="+new_pA_guid_key);

            //Debug.Log("=====> expression_AB (old): " + expression_AB);
            // EXPRESSIONS

            if (expression_AB != null)
            {
                expression_AB = expression_AB.Replace(old_pA_guid_key, new_pA_guid_key);
            }
            if (expression_BA != null)
            {
                expression_BA = expression_BA.Replace(old_pB_guid_key, new_pB_guid_key);
            }

            // ACTUAL PARAMETER GUIDS
            // replace old guids in the strings with the new guids
            pA_guid = AXUtilities.swapOutGuids(pA_guid, ref guidMap);
            pB_guid = AXUtilities.swapOutGuids(pB_guid, ref guidMap);

            // later, swap guids in pA_expression && pB
        }
Exemple #2
0
        public void saveToFile()
        {
            if (!string.IsNullOrEmpty(readIntoLibraryFromRelativeAXOBJPath))
            {
                string filepath = ArchimatixUtils.getAbsoluteLibraryPath(readIntoLibraryFromRelativeAXOBJPath);

                if (File.Exists(filepath))
                {
                    AX.SimpleJSON.JSONNode jn = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepath));

                    AX.SimpleJSON.JSONNode pon = jn[0];

                    if (jn ["parametric_objects"] != null)
                    {
                        pon = jn ["parametric_objects"] [0];
                    }

                    pon["name"] = Name;
                    pon["includeInSidebarMenu"] = includeInSidebarMenu.ToString();
                    pon["description"]          = description;

                    if (!string.IsNullOrEmpty(author))
                    {
                        pon["author"] = author;
                    }

                    if (!string.IsNullOrEmpty(tags))
                    {
                        pon["tags"] = tags;
                    }

                    if (!string.IsNullOrEmpty(documentationURL))
                    {
                        pon["documentationURL"] = documentationURL;
                    }

                    if (!string.IsNullOrEmpty(readIntoLibraryFromRelativeAXOBJPath))
                    {
                        pon["readIntoLibraryFromRelativeAXOBJPath"] = readIntoLibraryFromRelativeAXOBJPath;
                    }

                    // resave

                    File.WriteAllText(filepath, jn.ToString().Replace("\\", ""));

                    //Debug.Log(jn.ToString().Replace("\\",""));
                }
            }
        }
Exemple #3
0
        // SAVE WITHOUT DIALOG POPUP IF POSSIBLE

        public static void doSave_MenuItem(object obj)
        {
            //Debug.Log("LastLibraryPath="+EditorPrefs.GetString("LastLibraryPath"));
            //EditorPrefs.SetString("LastLibraryPath", "");
            // 1. Is there a folder pref?
            string absoluteFolderPath = EditorPrefs.GetString("LastLibraryPath");             // of the form "Assets/folder1/folder2..."



            if (string.IsNullOrEmpty(absoluteFolderPath))
            {
                // 1. THERE IS NO PREFERENCE FOR A FOLDER -- USE DEFAULT

                absoluteFolderPath = System.IO.Path.Combine(Application.dataPath, "ArchimatixLibrary");

                //Debug.Log("CASE #1: " + absoluteFolderPath);
                doSavePO_ToSpecifiedFolder(assertDefaultLibraryFolder(), obj);
            }
            else if (!System.IO.Directory.Exists(absoluteFolderPath))
            {
                // 2. THERE WAS A PREFERENCE, BUT IT DOES NOT EXIST -- Has the project name changed?
                string relativeFolderPath = ArchimatixUtils.getRelativeFilePath(absoluteFolderPath);

                string tryThisAbsolutePath = System.IO.Path.Combine(Application.dataPath, relativeFolderPath);

                //Debug.Log("CASE #2: " + tryThisAbsolutePath);


                if (System.IO.Directory.Exists(tryThisAbsolutePath))
                {
                    // 2a. There is an analagous folder in this project. go to file save panel with this as a suggestion
                    doSavePO_ToSpecifiedFolder(tryThisAbsolutePath, obj);
                }
                else
                {
                    // 2b. Go to file panel with default folder

                    AXParametricObject po = (AXParametricObject)obj;
                    doSave_SaveFilePanel(System.IO.Path.Combine(Application.dataPath, "ArchimatixLibrary"), po.Name, obj);
                }
            }
            else
            {
                //Debug.Log("CASE #3: " + absoluteFolderPath);
                // 3. The pref folder checks out, silently save to it...
                doSavePO_ToSpecifiedFolder(absoluteFolderPath, obj);
            }
        }
Exemple #4
0
        public void saveParametricObjectMetadata(AXParametricObject head_po)
        {
            //Debug.Log("SAVING head_po.author="+head_po.author);

            AX.SimpleJSON.JSONNode hn = AX.SimpleJSON.JSON.Parse(JSONSerializersAX.ParametricObjectAsJSON(head_po));

            string filename = ArchimatixUtils.getAbsoluteLibraryPath(head_po.readIntoLibraryFromRelativeAXOBJPath);

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

            jn["parametric_objects"][0] = hn;

            File.WriteAllText(filename, jn.ToString());

            rebuildTagListsFromExistingPOs();
        }
        public AXRelation(AXParameter _pA, AXParameter _pB)
        {
            if (_pA != null && _pB != null)
            {
                //Debug.Log ("Adding relation :: "+_pA.Parent.Name+"."+_pA.Name+" "+_pB.Parent.Name+"."+_pB.Name);
                pA = _pA;
                pB = _pB;

                pA_guid = pA.Guid;
                pB_guid = pB.Guid;

                // one expression would normally want to be the inverse of the other:
                //expression_AB = "IN";
                //expression_BA = "IN";
                expression_AB = ArchimatixUtils.guidToKey(pA.Guid);
                expression_BA = ArchimatixUtils.guidToKey(pB.Guid);
            }
        }
Exemple #6
0
        public static void removeLibraryItem(LibraryItem li)
        {
            string filepath = ArchimatixUtils.getAbsoluteLibraryPath(li.readIntoLibraryFromRelativeAXOBJPath);


            // First remove the item from the live library. THat way when the file is deleted, AX will not try to rebuild the library.
            //string nodeName = System.IO.Path.GetFileNameWithoutExtension(filepath);

            //LibraryItem li = ArchimatixEngine.library.getLibraryItem(nodeName);

            ArchimatixEngine.library.removeLibraryItemFromList(li);

            //string localFilepath = filepath.Substring(filepath.IndexOf("Assets/"));
            string axobjRelativePath = ArchimatixUtils.getRelativeFilePath(filepath);;



            // [Darkwell: change "undoable" to "cannot be undone" - 2016.06.02]
            if (EditorUtility.DisplayDialog("Delete Library Object?",
                                            "Are you sure you want to delete " + li.Name
                                            + "? This cannot be undone!", "Really Delete", "Cancel"))
            {
                AssetDatabase.DeleteAsset(axobjRelativePath);

                string prefix   = (li.is2D) ? "zz-AX-2DLib-" : "zz-AX-3DLib-";
                string filename = System.IO.Path.GetFileNameWithoutExtension(li.readIntoLibraryFromRelativeAXOBJPath);
                string noPrefixThumbnailPath   = System.IO.Path.ChangeExtension(li.readIntoLibraryFromRelativeAXOBJPath, ".jpg");
                string ThumbnailPathWithPrefix = noPrefixThumbnailPath.Replace(filename, prefix + filename);

                AssetDatabase.DeleteAsset(ThumbnailPathWithPrefix);

                //Debug.Log(thumbnailRelativePath + " deleted");

                // Refresh the AssetDatabase after all the changes
                AssetDatabase.Refresh();


                //library.readLibraryFromFiles();
            }
        }
Exemple #7
0
        public static AXParametricObject instantiateParametricObject(string readIntoLibraryFromRelativeAXOBJPath)
        {
            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>();
            }



            //Library.lastInstantiation = po;

            // This file path is where the metadata
            // for this head_po was found. Go back to this file
            // and get the rest of the data...
            string filepath = ArchimatixUtils.getAbsoluteLibraryPath(readIntoLibraryFromRelativeAXOBJPath);


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

            AX.SimpleJSON.JSONNode json = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepath));

            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");



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



            AXParametricObject head_po = poList[0];

            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.deselectAll();
            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.remapMaterialTools();
            model.autobuild();
            head_po.generator.adjustWorldMatrices();
            model.build();

            model.selectOnlyPO(head_po);

            //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);
        }
Exemple #8
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.");
        }
Exemple #9
0
        // DO THE ACTUAL SAVE
        public static void saveParametricObject(AXParametricObject po, bool withInputSubparts, string filepathname)
        {
            //Debug.Log(filepathname);
            //EditorUtility.DisplayDialog("Archimatix Library", "Saving to Library: This may take a few moments.", "Ok");

            po.readIntoLibraryFromRelativeAXOBJPath = ArchimatixUtils.getRelativeFilePath(filepathname);

            Library.recentSaveFolder = System.IO.Path.GetDirectoryName(filepathname);



            // If this head po has a grouperKey, lose it!
            // This is because when it is later instantiated,
            // that grouper may not exist or may not be the desired place for this.

            po.grouperKey = null;



            // gather relations as you go...
            List <AXRelation> rels = new List <AXRelation>();

            // BUILD JSON STRING
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append("\"parametric_objects\":[");
            sb.Append(JSONSerializersAX.ParametricObjectAsJSON(po));

            // gather rels
            foreach (AXParameter p in po.parameters)
            {
                foreach (AXRelation rr in p.relations)
                {
                    if (!rels.Contains(rr))
                    {
                        rels.Add(rr);
                    }
                }
            }



            // SUB NODES

            if (withInputSubparts)
            {
                // GATHER SUB_NODES
                //Debug.Log("Start gather");
                po.gatherSubnodes();
                //Debug.Log("End gather");

                foreach (AXParametricObject spo in po.subnodes)
                {
                    //Debug.Log("-- " + spo.Name);
                    sb.Append(',' + JSONSerializersAX.ParametricObjectAsJSON(spo));

                    // gather rels
                    foreach (AXParameter p in spo.parameters)
                    {
                        foreach (AXRelation rr in p.relations)
                        {
                            if (!rels.Contains(rr))
                            {
                                rels.Add(rr);
                            }
                        }
                    }
                }
            }
            sb.Append("]");



            // add relations to json
            string thecomma;

            // RELATIONS
            if (rels != null && rels.Count > 0)
            {
                sb.Append(", \"relations\": [");                                // begin parametric_objects

                thecomma = "";
                foreach (AXRelation rr in rels)
                {
                    sb.Append(thecomma + rr.asJSON());
                    thecomma = ", ";
                }
                sb.Append("]");
            }



            sb.Append("}");



            // *** SAVE AS ASSET ***



            // Since we have added the newItem to the live library,
            // generating this new file will not force a recreation of the library from the raw JSON file.
            File.WriteAllText(filepathname, sb.ToString());



            // THUMBNAIL TO PNG



            if (po.is2D())
            {
                Library.cache2DThumbnail(po);
            }
            else
            {
                Thumbnail.BeginRender();
                Thumbnail.render(po, true);
                Thumbnail.EndRender();
            }
            //string thumb_filename = System.IO.Path.ChangeExtension(filepathname, ".png");
            string filename = System.IO.Path.GetFileNameWithoutExtension(filepathname);

            string prefix         = (po.is2D()) ? "zz-AX-2DLib-" : "zz-AX-3DLib-";
            string thumb_filename = System.IO.Path.ChangeExtension(filepathname, ".jpg");

            thumb_filename = thumb_filename.Replace(filename, prefix + filename);



            byte[] bytes = po.thumbnail.EncodeToJPG();
            //File.WriteAllBytes(libraryFolder + "data/"+ po.Name + ".png", bytes);
            File.WriteAllBytes(thumb_filename, bytes);

            //AssetDatabase.Refresh();

            string thumbnailRelativePath = ArchimatixUtils.getRelativeFilePath(thumb_filename);

            //Debug.Log(path);
            AssetDatabase.ImportAsset(thumbnailRelativePath);
            TextureImporter importer = AssetImporter.GetAtPath(thumbnailRelativePath) as TextureImporter;

            if (importer != null)
            {
                importer.textureType    = TextureImporterType.GUI;
                importer.maxTextureSize = 256;



                                #if UNITY_5_5_OR_NEWER
                importer.textureCompression = TextureImporterCompression.Uncompressed;
                                #else
                importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
                                #endif
            }

            AssetDatabase.WriteImportSettingsIfDirty(thumbnailRelativePath);


            // Save the recent path to prefs
            EditorPrefs.SetString("LastLibraryPath", System.IO.Path.GetDirectoryName(filepathname));


            EditorUtility.DisplayDialog("Archimatix Library", "ParametricObject saved to " + System.IO.Path.GetDirectoryName(thumbnailRelativePath) + " as " + filename, "Great, thanks!");

            Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(thumbnailRelativePath, typeof(Texture2D));



            LibraryItem newItem = new LibraryItem(po);
            newItem.icon = tex;
            ArchimatixEngine.library.addLibraryItemToList(newItem);
            ArchimatixEngine.library.sortLibraryItems();


            ArchimatixEngine.saveLibrary();



            AssetDatabase.Refresh();

            //Debug.Log("yo 2");
            //ArchimatixEngine.library.readLibraryFromFiles();
        }