Exemplo n.º 1
0
 private void GrasshopperDocumentClosed(GH_DocumentServer sender, GH_Document doc)
 {
     if (doc != null && (m_doc != null && doc.DocumentID == m_doc.DocumentID))
     {
         Dispose();
     }
 }
Exemplo n.º 2
0
        public static void LoadDoc(string file)
        {
            var io = new GH_DocumentIO();

            if (!io.Open(file))
            {
                throw new Exception("读取文档失败");
            }

            GH_DocumentServer server = Instances.DocumentServer;

            var doc = io.Document;

            if (server == null)
            {
                throw new Exception("读取文档失败");
            }

            server.AddDocument(doc);

            GH_Canvas activeCanvas = Instances.ActiveCanvas;

            if (activeCanvas == null)
            {
                throw new Exception("读取文档失败");
            }

            activeCanvas.Document            = doc;
            activeCanvas.Document.IsModified = false;
            activeCanvas.Refresh();
        }
Exemplo n.º 3
0
        public void BringToFront(bool restore = false)
        {
            GH_DocumentServer doc_server = Instances.DocumentServer;

            if (doc_server == null)
            {
                ErrorEvent(this, "No Document Server exist!");
                return;
            }

            GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString());

            if (doc == null)
            {
                return;
            }

            GH_Canvas activeCanvas = Instances.ActiveCanvas;

            if (activeCanvas == null)
            {
                ErrorEvent(this, "No Active Canvas exist!");
                return;
            }

            activeCanvas.Document = doc;
            activeCanvas.Refresh();

            IsTaskRestore = restore;

            // SolutionEndCnt = 0;
            UpdateData(true, restore);
        }
Exemplo n.º 4
0
 private void documentServerOnDocumentClosed(GH_DocumentServer sender, GH_Document doc)
 {
     if (this.ghDocument != null && doc.DocumentID == this.ghDocument.DocumentID)
     {
         this.disconnect();
     }
 }
Exemplo n.º 5
0
 private void DocumentServer_DocumentRemoved(GH_DocumentServer sender, GH_Document doc)
 {
     if (doc.DocumentID == Document.DocumentID)
     {
         DocumentIsClosing = true;
     }
 }
Exemplo n.º 6
0
 private void OnDocumentClose(GH_DocumentServer sender, GH_Document doc)
 {
     if (_localReceiverPipe != null)
     {
         _localReceiverPipe.ClosePipe();
         _localReceiverPipe = null;
     }
 }
Exemplo n.º 7
0
 private void OnDocumentClose(GH_DocumentServer sender, GH_Document doc)
 {
     CloseLocalPipe();
     if (_webPipe != null)
     {
         _webPipe.ClosePipe();
         _webPipe = null;
     }
 }
Exemplo n.º 8
0
        private void LoadGhDocument()
        {
            if (content.type != TaskContentType.file)
            {
                return;
            }

            string file = content.value;

            if (!File.Exists(file))
            {
                ErrorEvent(this, "Work file is not exist!");
                return;
            }
            GH_DocumentIO io = new GH_DocumentIO();

            io.Open(file);

            GH_Document doc = GH_Document.DuplicateDocument(io.Document);

            if (doc == null)
            {
                ErrorEvent(this, "Cannot read this file!");
                return;
            }

            GH_DocumentServer server = Instances.DocumentServer;

            if (server == null)
            {
                ErrorEvent(this, "No Document Server exist!");
                return;
            }

            server.AddDocument(doc);

            doc.Properties.ProjectFileName = ID.ToString();

            GH_Canvas activeCanvas = Instances.ActiveCanvas;

            if (activeCanvas == null)
            {
                ErrorEvent(this, "No Active Canvas exist!");
                return;
            }

            activeCanvas.Document            = doc;
            activeCanvas.Document.IsModified = false;
            activeCanvas.Refresh();

            // SolutionEndCnt = 0;
            doc.SolutionEnd += Doc_SolutionEnd;
            UpdateData(true);
        }
Exemplo n.º 9
0
 private void DocumentServer_DocumentAdded(GH_DocumentServer sender, GH_Document doc)
 {
     if (!External.ActivationGate.IsOpen)
     {
         if (GH_Document.EnableSolutions)
         {
             GH_Document.EnableSolutions = false;
             EnableSolutions             = true;
         }
     }
 }
Exemplo n.º 10
0
        private void LoadGhDocument(string file)
        {
            if (!System.IO.File.Exists(file))
            {
                return;
            }
            GH_DocumentIO io = new GH_DocumentIO();

            io.Open(file);

            GH_Document doc = GH_Document.DuplicateDocument(io.Document);

            if (doc == null)
            {
                return;
            }

            GH_DocumentServer server = Instances.DocumentServer;

            if (server == null)
            {
                return;
            }

            server.AddDocument(doc);

            doc.Properties.ProjectFileName = ID.ToString();

            GH_Canvas activeCanvas = Instances.ActiveCanvas;

            if (activeCanvas == null)
            {
                return;
            }

            activeCanvas.Document            = doc;
            activeCanvas.Document.IsModified = false;
            activeCanvas.Refresh();

            doc.SolutionEnd += Doc_SolutionEnd;
        }
Exemplo n.º 11
0
 private void GrasshopperDocumentClosed(GH_DocumentServer sender, GH_Document doc)
 {
     if (doc != null && (m_doc != null && doc.DocumentID == m_doc.DocumentID))
       {
     Dispose();
       }
 }
Exemplo n.º 12
0
 private void CanvasCreatedEvent(GH_DocumentServer server, GH_Document doc)
 {
     AddSpeckleMenu(null, null);
 }
Exemplo n.º 13
0
        private void StoreOutput()
        {
            DebugEvent("Start Store Output");
            GH_DocumentServer doc_server = Instances.DocumentServer;

            if (doc_server == null)
            {
                throw new Exception("No Document Server exist!");
            }

            GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString());

            if (doc == null)
            {
                throw new Exception("Tasker 未找到GH_Document");
            }

            if (string.IsNullOrEmpty(workspace) || string.IsNullOrEmpty(ticket))
            {
                throw new Exception("工作目录和Ticket为空");
            }

            string outDir = Path.Combine(taskspace, ID.ToString(), ticket);

            var hooks = doc.ClusterOutputHooks();

            if (hooks == null)
            {
                return;
            }

            foreach (var hook in hooks)
            {
                string info = hook.CustomDescription;
                if (string.IsNullOrEmpty(info))
                {
                    continue;
                }
                var paraMap = ConvertUrlParam(info);

                if (!paraMap.TryGetValue("Index", out string index) ||
                    !paraMap.TryGetValue("Type", out string type))
                {
                    continue;
                }

                DebugEvent($"Index: {index}; Type: {type}");

                string fileName = Path.Combine(outDir, index + "@" + DateTime.Now.ToString("HH-mm-ss MM-dd"));

                var volatileData = hook.VolatileData;

                if (volatileData.IsEmpty)
                {
                    continue;
                }

                dynamic content = null;

                switch (type)
                {
                case "CSV":
                {
                    var           allData = volatileData.AllData(true);
                    List <string> sList   = new List <string>();
                    allData.ToList().ForEach(el =>
                        {
                            GH_Convert.ToString(el, out string tmp, GH_Conversion.Both);
                            sList.Add(tmp);
                        });

                    string csv = string.Join(Environment.NewLine, sList);

                    fileName += ".csv";
                    File.WriteAllText(fileName, csv, Encoding.UTF8);
                    content = fileName;
                    break;
                }

                case "3DM":
                {
                    fileName += ".3dm";

                    File3dmWriter writer = new File3dmWriter(fileName);

                    foreach (var data in volatileData.AllData(true))
                    {
                        GeometryBase obj = GH_Convert.ToGeometryBase(data);

                        if (obj == null)
                        {
                            continue;
                        }

                        string layer = obj.GetUserString("Layer");
                        if (layer == null)
                        {
                            continue;
                        }
                        ObjectAttributes att = new ObjectAttributes
                        {
                            LayerIndex = writer.GetLayer(layer, Color.Black)
                        };

                        writer.ObjectMap.Add(att, obj);
                    }

                    writer.Write();
                    content = fileName;
                    break;
                }

                case "Data":
                {
                    try
                    {
                        GH_Structure <IGH_Goo> tree = volatileData as GH_Structure <IGH_Goo>;

                        content = IO.SerializeGrasshopperData(tree, hook.CustomName, volatileData.IsEmpty);
                    }
                    catch (Exception ex)
                    {
                        ErrorEvent(this, ex.Message);
                    }

                    break;
                }

                case "EPS":
                {
                    List <GeometryBase> objs = new List <GeometryBase>();

                    foreach (var data in volatileData.AllData(true))
                    {
                        if (data == null)
                        {
                            continue;
                        }
                        GeometryBase obj = GH_Convert.ToGeometryBase(data);
                        if (obj == null)
                        {
                            continue;
                        }

                        objs.Add(obj);
                    }

                    if (!Directory.Exists(fileName))
                    {
                        Directory.CreateDirectory(fileName);
                    }

                    content = JsonConvert.SerializeObject(SaveAdobeDocument(fileName, objs, AdobeDocType.EPS));
                    break;
                }

                case "PDF":
                {
                    List <GeometryBase> objs = new List <GeometryBase>();

                    fileName += ".pdf";

                    foreach (var data in volatileData.AllData(true))
                    {
                        if (data == null)
                        {
                            continue;
                        }
                        GeometryBase obj = GH_Convert.ToGeometryBase(data);
                        if (obj == null)
                        {
                            continue;
                        }

                        objs.Add(obj);
                    }

                    var res = SaveAdobeDocument(fileName, objs, AdobeDocType.PDF);
                    if (res == null || res.Count == 0)
                    {
                        break;
                    }
                    content = res[0];
                    break;
                }

                case "RhinoPDF":
                {
                    var pdf = FilePdf.Create();

                    fileName += ".pdf";

                    DebugEvent("RhinoPDF Begin");

                    foreach (var page in volatileData.AllData(true))
                    {
                        DebugEvent("RhinoPDF got 1 page");
                        if (!page.CastTo(out RhinoPageView view))
                        {
                            DebugEvent(string.Format("{0} can not convert to RhinoPageView", page.GetType()));
                            continue;
                        }

                        DebugEvent("Data is converted to RhinoPage");

                        ViewCaptureSettings settings = new ViewCaptureSettings(view, 300)
                        {
                            OutputColor = ViewCaptureSettings.ColorMode.DisplayColor,
                            RasterMode  = true
                        };

                        pdf.AddPage(settings);
                    }

                    pdf.Write(fileName);
                    content = fileName;
                    break;
                }

                case "DXF":
                {
                    break;
                }

                default:
                    break;
                }

                StoreEvent(this, new JObject
                {
                    ["route"]   = "task-stored",
                    ["id"]      = ID.ToString(),
                    ["index"]   = index.ToString(),
                    ["type"]    = type,
                    ["content"] = content
                }.ToString());
            }
        }
Exemplo n.º 14
0
        private void UpdateData(bool recomputeOnTheEnd, bool restore = false)
        {
            if (dataList.Count == 0 || dataList == null)
            {
                return;
            }

            GH_DocumentServer doc_server = Instances.DocumentServer;

            if (doc_server == null)
            {
                ErrorEvent(this, "No Document Server exist!");
                return;
            }

            GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString());

            if (doc == null)
            {
                return;
            }

            var hooks = doc.ClusterInputHooks();

            if (!restore)
            {
                var rndData = dataList.FindAll(data => data.type == "4" || data.type == "5");

                history.Add(new TaskRecord
                {
                    name      = name,
                    TaskID    = ID,
                    HistoryID = Guid.NewGuid(),
                    date      = DateTime.Now,
                    table     = dataTable,
                    taskDatas = JsonConvert.SerializeObject(rndData)
                });
            }

            foreach (var hook in hooks)
            {
                TaskData data = dataList.Find(x => x.name == hook.CustomNickName || x.dataID == hook.CustomNickName);

                if (data == null)
                {
                    continue;
                }

                GH_Structure <IGH_Goo> m_data;

                if (data.type == "5")
                {
                    m_data = IO.DeserializeGrasshopperData(Convert.FromBase64String((string)data.value));
                }
                else
                {
                    m_data = SingleDataStructrue(data.value);
                }

                hook.ClearPlaceholderData();

                // if (Equals(hook.VolatileData, m_data)) continue;
                if (!m_data.IsEmpty)
                {
                    hook.SetPlaceholderData(m_data);
                }

                if (!recomputeOnTheEnd)
                {
                    hook.ExpireSolution(true);
                }
            }

            // for data placeholder inside cluster (deep = 1)

            var clusters = new List <GH_Cluster>();

            foreach (var obj in doc.Objects)
            {
                if (!(obj is GH_Cluster cluster))
                {
                    continue;
                }
                clusters.Add(cluster);
            }

            if (clusters.Count == 0)
            {
                return;
            }


            foreach (var cluster in clusters)
            {
                foreach (var obj in cluster.Document("").Objects)
                {
                    if (!(obj is IGH_Param param))
                    {
                        continue;
                    }

                    string nickname = param.NickName;

                    if (!nickname.StartsWith("@", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    TaskData data = dataList.Find(x => x.name == nickname || x.dataID == nickname);

                    if (data == null)
                    {
                        continue;
                    }

                    Utility.InvokeMethod(param, "Script_ClearPersistentData");
                    Utility.InvokeMethod(param, "Script_AddPersistentData", new List <object>()
                    {
                        data.value
                    });

                    if (!recomputeOnTheEnd)
                    {
                        param.ExpireSolution(true);
                    }
                    if (!recomputeOnTheEnd)
                    {
                        cluster.ExpireSolution(true);
                    }
                }
            }

            if (recomputeOnTheEnd)
            {
                doc.NewSolution(true);
            }

            GH_Canvas activeCanvas = Instances.ActiveCanvas;

            if (activeCanvas == null)
            {
                ErrorEvent(this, "No Active Canvas exist!");
                return;
            }

            activeCanvas.Document.IsModified = false;
            activeCanvas.Refresh();

            dataList.Clear();
        }
Exemplo n.º 15
0
 private void DocumentServer_DocumentAdded(GH_DocumentServer sender, GH_Document doc)
 {
     doc.SolutionEnd += Definition_SolutionEnd;
     definition       = doc;
 }