Example #1
0
        internal static void Load(DOC.DocProject docProject, string filename)
        {
            for (int iNS = 0; iNS < mvdXML.Namespaces.Length; iNS++)
            {
                string xmlns = mvdXML.Namespaces[iNS];
                using (FormatXML format = new FormatXML(filename, typeof(mvdXML), xmlns))
                {
                    try
                    {
                        format.Load();
                        mvdXML mvd = (mvdXML)format.Instance;
                        Program.ImportMvd(mvd, docProject, filename);
                        break;
                    }
                    catch (InvalidOperationException xx)
                    {
                        // keep going until successful

                        if (iNS == mvdXML.Namespaces.Length - 1)
                        {
                            throw new InvalidOperationException("The file is not of a supported format (mvdXML 1.0 or mvdXML 1.1).");
                        }
                    }
                    catch (Exception xx)
                    {
                        xmlns = null;
                    }
                }
            }
        }
Example #2
0
        public void Save()
        {
            svg s = new svg();

            s.version = "1.1";
            s.width   = (this.m_schema.DiagramPagesHorz * CtlExpressG.PageX).ToString();
            s.height  = (this.m_schema.DiagramPagesVert * CtlExpressG.PageY).ToString();

            foreach (DocEntity docEnt in this.m_schema.Entities)
            {
                g group = SaveDefinition(docEnt, null);
                s.g.Add(group);
                if (group != null)
                {
                    SaveTree(group, docEnt.Tree, null, true);

                    foreach (DocAttribute docAttr in docEnt.Attributes)
                    {
                        if (docAttr.DiagramLine != null && docAttr.DiagramLine.Count >= 2)
                        {
                            g attr = new g();
                            group.groups.Add(attr);
                            attr.id = docAttr.Name;

                            bool?linestyle = false;
                            if (docAttr.IsOptional)
                            {
                                linestyle = null;
                            }
                            SaveLine(attr, docAttr.DiagramLine, null, linestyle);

                            // calculate midpoint of line
                            double mx = (docAttr.DiagramLine[0].X + docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].X) * 0.5;
                            double my = (docAttr.DiagramLine[0].Y + docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].Y) * 0.5;

                            // vex files define relative position
                            double rx = docAttr.DiagramLabel.X - docAttr.DiagramLine[0].X;
                            double ry = docAttr.DiagramLabel.Y - docAttr.DiagramLine[0].Y;

                            // calculate absolute position
                            double ax = mx + rx;
                            double ay = my + ry;

                            text t = new text();
                            attr.text.Add(t);
                            t.value = (docAttr.Name + " " + docAttr.GetAggregationExpression()).Trim();
                            t.fill  = "black";
                            t.x     = (ax * CtlExpressG.Factor).ToString();
                            t.y     = (ay * CtlExpressG.Factor).ToString();
                            t.alignment_baseline = "middle";
                            t.text_anchor        = "middle";
                            t.font_size          = "10";
                            t.font_family        = "Arial, Helvetica, sans-serif";
                        }
                    }
                }
            }

            foreach (DocType docEnt in this.m_schema.Types)
            {
                g group = SaveDefinition(docEnt, null);
                s.g.Add(group);
                if (docEnt is DocSelect)
                {
                    DocSelect docSelect = (DocSelect)docEnt;
                    SaveTree(group, docSelect.Tree, null, false);
                }
            }

            foreach (DocPrimitive docEnt in this.m_schema.Primitives)
            {
                g group = SaveDefinition(docEnt, null);
                s.g.Add(group);
            }

            foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs)
            {
                g r = SaveDefinition(docRef, null);
                s.g.Add(r);
                foreach (DocDefinitionRef docDef in docRef.Definitions)
                {
                    g group = SaveDefinition(docDef, docRef.Name + "\r\n" + docDef.Name);
                    r.groups.Add(group);

                    SaveTree(group, docDef.Tree, null, true);
                }
            }

            foreach (DocPageTarget docTarget in this.m_schema.PageTargets)
            {
                g target = SaveDefinition(docTarget, null);
                s.g.Add(target);

                SaveLine(target, docTarget.DiagramLine, null, false);

                foreach (DocPageSource docSource in docTarget.Sources)
                {
                    g source = SaveDefinition(docSource, null);
                    target.groups.Add(source);
                }
            }

            // grid lines
            if (this.m_format == DiagramFormat.ExpressG)
            {
                g grid = new g();
                s.g.Add(grid);
                for (int iPageY = 0; iPageY < m_schema.DiagramPagesVert; iPageY++)
                {
                    for (int iPageX = 0; iPageX < m_schema.DiagramPagesHorz; iPageX++)
                    {
                        rect r = new rect();
                        r.x      = (iPageX * CtlExpressG.PageX).ToString();
                        r.y      = (iPageY * CtlExpressG.PageY).ToString();
                        r.width  = CtlExpressG.PageX.ToString();
                        r.height = CtlExpressG.PageY.ToString();
                        r.fill   = "none";
                        r.stroke = "lime";
                        grid.rect.Add(r);
                    }
                }
            }

            using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg"))
            {
                format.Instance = s;
                format.Save();
            }
        }
Example #3
0
        public void Load()
        {
            svg s = null;

            using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg"))
            {
                format.Load();
                s = format.Instance as svg;
            }

            if (s == null)
            {
                return;
            }

            // apply diagram to existing schema elements
            foreach (g group in s.g)
            {
                // primitive
                DocDefinition docDef = null;
                switch (group.id)
                {
                case "INTEGER":
                case "REAL":
                case "BOOLEAN":
                case "LOGICAL":
                case "STRING":
                case "BINARY":
                    docDef      = new DocPrimitive();
                    docDef.Name = group.id;
                    m_schema.Primitives.Add((DocPrimitive)docDef);
                    break;

                default:
                    docDef = this.m_schema.GetDefinition(group.id);
                    break;
                }

                if (docDef != null)
                {
                    docDef.DiagramRectangle = LoadRectangle(group);

                    // attributes, supertype...
                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        LoadTree(group, docEnt.Tree);

                        foreach (g subgroup in group.groups)
                        {
                            foreach (DocAttribute docAttr in docEnt.Attributes)
                            {
                                if (docAttr.Name.Equals(subgroup.id))
                                {
                                    LoadLine(subgroup, docAttr.DiagramLine);

                                    if (subgroup.text.Count == 1)
                                    {
                                        double ax = Double.Parse(subgroup.text[0].x) / CtlExpressG.Factor;
                                        double ay = Double.Parse(subgroup.text[0].y) / CtlExpressG.Factor;

                                        docAttr.DiagramLabel   = new DocRectangle();
                                        docAttr.DiagramLabel.X = ax;
                                        docAttr.DiagramLabel.Y = ay;
                                    }

                                    break;
                                }
                            }
                        }

                        // base type???
                    }
                    else if (docDef is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)docDef;
                        LoadLine(group, docDefined.DiagramLine);
                    }
                    else if (docDef is DocSelect)
                    {
                        DocSelect docSelect = (DocSelect)docDef;
                        LoadTree(group, docSelect.Tree);
                    }
                }
                else
                {
                    // schema ref
                    DocSchema docTargetSchema = this.m_project.GetSchema(group.id);
                    if (docTargetSchema != null)
                    {
                        DocSchemaRef docSchemaRef = new DocSchemaRef();
                        docSchemaRef.Name = group.id;
                        this.m_schema.SchemaRefs.Add(docSchemaRef);

                        foreach (g subgroup in group.groups)
                        {
                            DocDefinition docTargetDef = docTargetSchema.GetDefinition(subgroup.id);
                            if (docTargetDef != null)
                            {
                                DocDefinitionRef docDefRef = new DocDefinitionRef();
                                docDefRef.Name = subgroup.id;
                                docSchemaRef.Definitions.Add(docDefRef);
                                docDefRef.DiagramRectangle = LoadRectangle(subgroup);

                                LoadTree(subgroup, docDefRef.Tree);
                            }
                        }
                    }
                    else
                    {
                        // primitive?

                        // page targets
                        DocPageTarget docPageTarget = new DocPageTarget();
                        docPageTarget.Name = group.id;
                        this.m_schema.PageTargets.Add(docPageTarget);
                        docPageTarget.DiagramRectangle = LoadRectangle(group);
                        //...docPageTarget.Definition =
                        LoadLine(group, docPageTarget.DiagramLine);

                        foreach (g subgroup in group.groups)
                        {
                            DocPageSource docPageSource = new DocPageSource();
                            docPageSource.Name = subgroup.id;
                            docPageTarget.Sources.Add(docPageSource);
                            docPageSource.DiagramRectangle = LoadRectangle(subgroup);
                        }
                    }
                }
            }
        }
Example #4
0
        public void Save()
        {
            // build map of enumerations
            Dictionary <string, DocPropertyEnumeration> mapPropEnum = new Dictionary <string, DocPropertyEnumeration>();

            foreach (DocPropertyEnumeration docEnum in this.m_project.PropertyEnumerations)
            {
                if (!mapPropEnum.ContainsKey(docEnum.Name))
                {
                    mapPropEnum.Add(docEnum.Name, docEnum);
                }
            }

            using (Package zip = ZipPackage.Open(this.m_stream, FileMode.Create))
            {
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        if (this.m_type == null || this.m_type == typeof(DocPropertySet))
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                if (m_included == null || this.m_included.ContainsKey(docPset))
                                {
                                    if (docPset.IsVisible())
                                    {
                                        Uri         uri  = PackUriHelper.CreatePartUri(new Uri(docPset.Name + ".xml", UriKind.Relative));
                                        PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);
                                        using (Stream refstream = part.GetStream())
                                        {
                                            refstream.SetLength(0);
                                            PropertySetDef psd = Program.ExportPsd(docPset, mapPropEnum, this.m_project);
                                            using (FormatXML format = new FormatXML(refstream, typeof(PropertySetDef), PropertySetDef.DefaultNamespace, null))
                                            {
                                                format.Instance = psd;
                                                format.Save();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (this.m_type == null || this.m_type == typeof(DocQuantitySet))
                        {
                            foreach (DocQuantitySet docQset in docSchema.QuantitySets)
                            {
                                if (m_included == null || this.m_included.ContainsKey(docQset))
                                {
                                    Uri         uri  = PackUriHelper.CreatePartUri(new Uri(docQset.Name + ".xml", UriKind.Relative));
                                    PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);
                                    using (Stream refstream = part.GetStream())
                                    {
                                        refstream.SetLength(0);
                                        QtoSetDef psd = Program.ExportQto(docQset, this.m_project);
                                        using (FormatXML format = new FormatXML(refstream, typeof(QtoSetDef), PropertySetDef.DefaultNamespace, null))
                                        {
                                            format.Instance = psd;
                                            format.Save();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public static void Download(DocProject project, System.ComponentModel.BackgroundWorker worker, string baseurl, string username, string password)
        {
            if (project.Sections[4].Schemas.Count == 0)
            {
                project.Sections[4].Schemas.Add(new DocSchema());
            }

            string url = baseurl + "api/4.0/session/login?email=" + HttpUtility.UrlEncode(username) + "&password="******"POST";
            request.ContentLength = 0;
            request.ContentType   = "application/x-www-form-urlencoded";
            request.Accept        = "application/json";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            System.IO.Stream       stream = response.GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(stream);
            string body = reader.ReadToEnd();

            string cookie = response.Headers.Get("Set-Cookie");

            string[] parts     = cookie.Split(new char[] { ';', ',' }); // bug? comma separates session ID
            string   match     = "peregrineapisessionid=";
            string   sessionid = null;

            foreach (string part in parts)
            {
                if (part.StartsWith(match))
                {
                    sessionid = part.Substring(match.Length);
                    break;
                }
            }

            /*-Get all users:
             * var client = new RestClient("http://test.bsdd.buildingsmart.org/api/4.0/IfdUser/");
             * var request = new RestRequest(Method.GET);
             * request.AddHeader("cookie", "peregrineapisessionid=thesessionid");
             * request.AddHeader("accept", "application/json");
             * request.AddHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
             * IRestResponse response = client.Execute(request);*/

            /*- Get all languages:
             * var client = new RestClient("http://test.bsdd.buildingsmart.org/api/4.0/IfdLanguage/");
             * var request = new RestRequest(Method.GET);
             * request.AddHeader("cookie", "peregrineapisessionid={{sessionId}}");
             * request.AddHeader("accept", "application/json");
             * request.AddHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
             * IRestResponse response = client.Execute(request);*/
            request               = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdLanguage/");
            request.Method        = "GET";
            request.ContentLength = 0;
            request.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
            request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid);
            request.Accept = "application/json";
            response       = (HttpWebResponse)request.GetResponse();

            stream = response.GetResponseStream();
            reader = new System.IO.StreamReader(stream);
            body   = reader.ReadToEnd();

            body.ToString();

            request               = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdConcept/search/filter/language/1ASQw0qJqHuO00025QrE$V/type/NEST/Pset_*");
            request.Method        = "GET";
            request.ContentLength = 0;
            request.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
            request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid);
            request.Accept = "application/json";
            response       = (HttpWebResponse)request.GetResponse();

            stream = response.GetResponseStream();
            reader = new System.IO.StreamReader(stream);
            body   = reader.ReadToEnd();

            System.IO.Stream       ms     = new System.IO.MemoryStream();
            System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
            writer.Write(body);
            writer.Flush();
            ms.Position = 0;
            //System.IO.MemoryStream mstream = new System.IO.MemoryStream()

            ResponseSearch ifdRoot;

            try
            {
                DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings();
                //settings.UseSimpleDictionaryFormat = true;
                System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResponseSearch));
                ifdRoot = (ResponseSearch)ser.ReadObject(ms);
            }
            catch
            {
                return;
            }

            // PERF: consider API on server that would return all information at once (currently 150+ round trips)
            for (int iConc = 0; iConc < ifdRoot.IfdConcept.Length; iConc++)
            {
                IfdConcept concept = ifdRoot.IfdConcept[iConc];
                worker.ReportProgress((int)(100.0 * (double)iConc / (double)ifdRoot.IfdConcept.Length));

                // api/4.0/IfdPSet/{guid}/ifcVersion/{ifcVersion}/XML

#if true                                   //figure out version info // language code starting at 5th character then lowercase -- e.g. "IFC-2X4" -> "2x4"
                string ifcversion = "2x4"; // "IFC4";// "ifc-2X4"; //???? what should this be ???? -- code "ifc-2X4" appears in headers; "IFC-2x4" appears in UI; "IFC4" is official schema name
                request               = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdPSet/" + concept.guid + "/ifcVersion/" + ifcversion + "/XML");
                request.Method        = "GET";
                request.ContentLength = 0;
                request.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
                request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid);
                request.Accept = "application/xml";
#endif
#if false // worked April 1, but no longer works as of 2017-06-13 (http body returns "null" -- as in 4 character string) -- issue with test server -- CoBuilder merge wiped out content??
                request               = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdConcept/" + concept.guid + "/children");
                request.Method        = "GET";
                request.ContentLength = 0;
                request.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
                request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid);
                request.Accept = "application/json";
                //request.Accept = "application/xml";
#endif
                try
                {
                    response = (HttpWebResponse)request.GetResponse();

                    stream = response.GetResponseStream();


                    reader = new System.IO.StreamReader(stream);
                    body   = reader.ReadToEnd();
                    if (body != null && body != "null") // !!!!
                    {
                        ms     = new MemoryStream();
                        writer = new StreamWriter(ms, Encoding.Unicode);
                        writer.Write(body);
                        writer.Flush();
                        ms.Position = 0;

                        try
                        {
                            using (FormatXML format = new FormatXML(ms, typeof(PropertySetDef), null, null))
                            {
                                format.Load();
                                PropertySetDef psd = (PropertySetDef)format.Instance;
                                Program.ImportPsd(psd, project);
                            }
                        }
                        catch
                        {
                            System.Diagnostics.Debug.WriteLine("Error downloading property set: " + concept.guid.ToString());
                        }


#if false
                        ResponsePset ifdResponse;
                        DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings();
                        //settings.UseSimpleDictionaryFormat = true;
                        System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResponsePset));

                        try
                        {
                            System.IO.Stream       xs      = new System.IO.MemoryStream();
                            System.IO.StreamWriter xwriter = new System.IO.StreamWriter(xs);
                            xwriter.Write(body);
                            xwriter.Flush();
                            xs.Position = 0;

                            ifdResponse = (ResponsePset)ser.ReadObject(xs);

                            ifdResponse.ToString();


                            DocPropertySet docPset = new DocPropertySet();
                            docPset.Uuid = new Guid();// concept.guid;
                            foreach (IfdName ifdName in concept.fullNames)
                            {
                                // if english
                                if (ifdName.languageFamily == "IFC")
                                {
                                    docPset.Name = ifdName.name;
                                }
                                else
                                {
                                    DocLocalization docLoc = new DocLocalization();
                                    docLoc.Locale = ifdName.language.languageCode;
                                    docLoc.Name   = ifdName.name;
                                    docPset.Localization.Add(docLoc);
                                }
                            }
                            docPset.Documentation = concept.definitions.description;
                            project.Sections[4].Schemas[0].PropertySets.Add(docPset);

                            foreach (IfdConceptInRelationship ifdProp in ifdResponse.IfdConceptInRelationship)
                            {
                                //ifdProp.fullNames[0].
                                DocProperty docProp = new DocProperty();
                                if (ifdProp.definitions != null)
                                {
                                    docProp.Documentation = ifdProp.definitions.description;
                                }
                                docPset.Properties.Add(docProp);

                                foreach (IfdName ifdName in ifdProp.fullNames)
                                {
                                    // if english
                                    if (ifdName.languageFamily == "IFC")
                                    {
                                        //docProp.Name = ifdName.name;
                                        string[] nameparts = ifdName.name.Split('.');
                                        if (nameparts.Length == 2)
                                        {
                                            docPset.Name = nameparts[0];
                                            docProp.Name = nameparts[1];
                                        }
                                    }
                                    else
                                    {
                                        DocLocalization docLoc = new DocLocalization();
                                        docLoc.Locale = ifdName.language.languageCode;
                                        docLoc.Name   = ifdName.name;
                                        docProp.Localization.Add(docLoc);
                                    }
                                }
                            }
                        }
#endif
                    }
                }
                catch
                {
                    //...
                    return;
                }
            }
        }