Exemplo n.º 1
0
        /// <summary>
        /// Returns all the speckle stream states present in the file.
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static List <StreamState> ReadState(DgnFile file)
        {
            var states = new List <StreamState>();

            try
            {
                FindInstancesScope scope = FindInstancesScope.CreateScope(file, new FindInstancesScopeOption(DgnECHostType.All));
                var schema = (ECSchema)DgnECManager.Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);

                if (schema == null)
                {
                    return(states);
                }

                ECQuery readWidget = new ECQuery(schema.GetClass(className));
                readWidget.SelectClause.SelectAllProperties = true;

                using (DgnECInstanceCollection ecInstances = DgnECManager.Manager.FindInstances(scope, readWidget))
                {
                    var streamStatesInstance = ecInstances.First();
                    if (streamStatesInstance != null)
                    {
                        var str = streamStatesInstance[propertyName].StringValue;
                        states = JsonConvert.DeserializeObject <List <StreamState> >(str);
                    }
                }

                return(states);
            }
            catch (Exception e)
            {
                return(new List <StreamState>());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the stream states to the current schema.
        /// </summary>
        /// <param name="streamStates"></param>
        public static void WriteStreamStateList(DgnFile File, List <StreamState> streamStates)
        {
            DgnECManager       Manager = DgnECManager.Manager;
            FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));

            IECSchema schema  = RetrieveSchema(File, scope);
            IECClass  ecClass = schema.GetClass(className);

            ECQuery readWidget = new ECQuery(ecClass);

            readWidget.SelectClause.SelectAllProperties = true;

            using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget))
            {
                foreach (IDgnECInstance instance in instances)
                {
                    instance.Delete();
                }
            }

            DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass);

            var data = JsonConvert.SerializeObject(streamStates) as string;
            StandaloneECDInstance _instance = instanceEnabler.SharedWipInstance;

            _instance.SetAsString(propertyName, data);
            instanceEnabler.CreateInstanceOnFile(File, _instance);
        }
Exemplo n.º 3
0
            public static DgnECInstanceCollection RetrieveInstances()
            {
                DgnFile      File    = Session.Instance.GetActiveDgnFile();
                DgnECManager Manager = DgnECManager.Manager;

                FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
                IECSchema          schema  = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
                IECClass           ecClass = schema.GetClass(className);

                ECQuery readWidget = new ECQuery(ecClass);

                readWidget.SelectClause.SelectAllProperties = true;
                DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget);

                return(instances);
            }
Exemplo n.º 4
0
        public void FindInstances()
        {
            DgnECManager       manager = DgnECManager.Manager;
            FindInstancesScope scope   = FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.Element, true));
            ECQuery            query   = new ECQuery(Extension.Utilities.GetActiveModelAllClasses());

            query.SelectClause.SelectAllProperties = true;
            manager.FindInstances(scope, query);
            //每次寻找实例不对啊,需要打开Property窗口后才能正确显示
            using (DgnECInstanceCollection ecInstances = manager.FindInstances(scope, query))
            {
                foreach (var ecin in ecInstances)
                {
                    foreach (IECProperty itemProp in ecin.ClassDefinition.Properties(false))
                    {
                        var instanceitem = new Instance();
                        instanceitem.ClassName    = ecin.ClassDefinition.DisplayLabel;
                        instanceitem.PropertyName = itemProp.Name;
                        string type = itemProp.Type.Name.ToLower();
                        instanceitem.TypeName = type;
                        IECPropertyValue propvalue = ecin.GetPropertyValue(itemProp.Name);

                        switch (type)
                        {
                        case "string":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : "";
                            break;

                        case "boolean":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : "";
                            break;

                        case "int":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.IntValue.ToString() : "";
                            break;

                        case "double":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.DoubleValue.ToString() : "";
                            break;
                        }
                        Instances.Add(instanceitem);
                    }
                }
            }
        }
Exemplo n.º 5
0
            public static IDgnECInstance RetrieveInstance(StreamState streamState)
            {
                DgnFile      File    = Session.Instance.GetActiveDgnFile();
                DgnECManager Manager = DgnECManager.Manager;

                FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
                IECSchema          schema  = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
                IECClass           ecClass = schema.GetClass(className);

                ECQuery readWidget = new ECQuery(ecClass);

                readWidget.SelectClause.SelectAllProperties = true;
                DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget);

                var instance = instances.Where(x => x["Id"].StringValue == streamState.Stream.id).FirstOrDefault();

                return(instance);
            }
Exemplo n.º 6
0
        /// <summary>
        /// Проверка является ли элемент SPDS-элементом
        /// </summary>
        public static bool IsSPDSElement(this Element element)
        {
            CellHeaderElement cell = element as CellHeaderElement;

            if (cell == null)
            {
                return(false);
            }

            var manager = DgnECManager.Manager;

            using (DgnECInstanceCollection ecInstances =
                       manager.GetElementProperties(cell, ECQueryProcessFlags.SearchAllClasses))
            {
                return(ecInstances.FirstOrDefault(x =>
                                                  x.ClassDefinition.Name == ECCLASS_COMMON_NAME &&
                                                  x.ClassDefinition.Schema.Name == SCHEMA_NAME) != null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes the stream states to the current schema.
        /// </summary>
        /// <param name="streamStates"></param>
        public static void WriteStreamStateList(List <StreamState> streamStates)
        {
            DgnFile      File    = Session.Instance.GetActiveDgnFile();
            DgnECManager Manager = DgnECManager.Manager;

            FindInstancesScope scope  = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
            IECSchema          schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);

            if (schema == null)
            {
                schema = StreamStateListSchema.GetSchema();
            }

            IECClass ecClass = schema.GetClass(className);

            ECQuery readWidget = new ECQuery(ecClass);

            readWidget.SelectClause.SelectAllProperties = true;

            using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget))
            {
                foreach (IDgnECInstance instance in instances)
                {
                    instance.Delete();
                }
            }

            DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass);

            foreach (var streamState in streamStates)
            {
                var data = JsonConvert.SerializeObject(streamState) as string;
                StandaloneECDInstance instance = instanceEnabler.SharedWipInstance;

                instance.SetAsString("Id", streamState.Stream.id);
                instance.SetAsString("StreamData", data);

                instanceEnabler.CreateInstanceOnFile(File, instance);
            }
        }
Exemplo n.º 8
0
        private ECPropertyReader(Element element, string className)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // !проверка, что элемент добавлен в модель
            if (element.DgnModel == null || element.ElementId == null)
            {
                throw new ArgumentException(string.Format(
                                                "Couldn't read EC-properties from non-model element"));
            }

            this.element = element;

            using (DgnECInstanceCollection ecInstances = DgnECManager.Manager.
                                                         GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses))
            {
                ecInst = ecInstances.FirstOrDefault(x =>
                                                    x.ClassDefinition.Name == className); // EnumString.ToString(instType));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns all the speckle stream states present in the custom schema (schema is attached to file).
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static List <StreamState> ReadState(ECSchema schema)
        {
            DgnFile      File    = Session.Instance.GetActiveDgnFile();
            DgnECManager Manager = DgnECManager.Manager;

            try
            {
                ECQuery readWidget = new ECQuery(schema.GetClass(className));
                readWidget.SelectClause.SelectAllProperties = true;

                FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));

                var states = new List <StreamState>();
                using (DgnECInstanceCollection ecInstances = Manager.FindInstances(scope, readWidget))
                {
                    foreach (IDgnECInstance instance in ecInstances)
                    {
                        var id = instance["Id"].StringValue;
                        var streamStateData = instance["StreamData"].StringValue;
                        var state           = JsonConvert.DeserializeObject <StreamState>(streamStateData);
                        states.Add(state);
                    }
                }

                if (states != null)
                {
                    states.ForEach(x => x.Initialise(true));
                }

                return(states);
            }
            catch (Exception e)
            {
                return(new List <StreamState>());
            }
        }
Exemplo n.º 10
0
        public static IEnumerable <string> getSp3dXmlData(Element element, bool includeRelations = true)
        {
            var summary = new HashSet <string>();

            var manager = DgnECManager.Manager;

            manager.ActivateDgnECEvents();

            using (DgnECInstanceCollection ecInstances =
                       manager.GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses))
            {
                foreach (IDgnECInstance inst in ecInstances)
                {
                    //! если не удалить xmlns, то получим ошибку
                    // ~ "not absolut xmlns path"
                    string xmlData = Regex.Replace(getXmlFormECInstance(inst),
                                                   " xmlns=\"[^\"]+\"", "");
                    summary.Add(xmlData);

                    if (!includeRelations)
                    {
                        continue;
                    }

                    inst.SelectClause = inst.SelectClause ?? new SelectCriteria();
                    inst.SelectClause.SelectAllProperties  = true;
                    inst.SelectClause.SelectDistinctValues = true;
                    DgnSelectAllRelationshipsAccessor.SetIn(inst.SelectClause, true);

                    foreach (IECRelationshipInstance relInst in inst.GetRelationshipInstances())
                    {
                        var refInst = (IDgnECInstance)relInst.Source;

                        if (relInst.Source.ClassDefinition.Name == "P3DHangerPipeSupport")
                        {
                            FindInstancesScopeOption option = new FindInstancesScopeOption(DgnECHostType.Element);
                            FindInstancesScope       scope  =
                                FindInstancesScope.CreateScope(refInst.Element, option);

                            IECSchema schema = relInst.Source.ClassDefinition.Schema;

                            var query = QueryHelper.CreateQuery(schema, true,
                                                                relInst.Source.ClassDefinition.Name);
                            query.SelectClause.SelectAllProperties  = true;
                            query.SelectClause.SelectDistinctValues = true;

                            var findInsts = manager.FindInstances(scope, query);
                            if (findInsts.Count() > 0)
                            {
                                //! если не удалить xmlns, то получим ошибку
                                // ~ "not absolut xmlns path"
                                xmlData = Regex.Replace(
                                    getXmlFormECInstance(findInsts.First()),
                                    " xmlns=\"[^\"]+\"", "");
                                summary.Add(xmlData);
                            }
                        }
                    }
                }
            }

            return(summary);
        }
Exemplo n.º 11
0
        public static void Test(Element element)
        {
            if (element == null)
            {
                return;
            }

            // !проверка, что элемент добавлен в модель
            if (element.DgnModel == null || element.ElementId == null)
            {
                throw new ArgumentException(string.Format(
                                                "Couldn't read EC-properties from non-model element"));
            }



            TextNodeElement txtEl = element as TextNodeElement;

            if (txtEl != null)
            {
                foreach (var id in txtEl.GetTextPartIds(new TextQueryOptions()))
                {
                    var txtPart = txtEl.GetTextPart(id);
                    TextBlockProperties props = txtPart.GetProperties();
                    //txtPart.GetRunPropertiesForAdd()
                }
            }


            DgnECInstanceCollection ecInstances = DgnECManager.Manager.
                                                  GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses);

            //foreach(var linkId in element.GetLinkageIds())
            //{
            //    var link = element.GetLinkage(linkId);
            //    link = link;

            //    for (int i = 0; i < link.Size; ++i)
            //    {
            //        try
            //        {
            //            string str = link.ReadString();
            //        }
            //        catch (Exception)
            //        {
            //        }
            //    }

            //}


            System.Text.StringBuilder bldr = new System.Text.StringBuilder();

            foreach (IDgnECInstance inst in ecInstances)
            {
                bldr.AppendLine(string.Format("Inst: <{0}> ID=<{1}>",
                                              inst.ClassDefinition.Name, inst.InstanceId));
                foreach (IECPropertyValue propVal in inst)
                {
                    if (propVal.Property.Name == "Links")
                    {
                    }

                    if (propVal.Type is ECArrayType)
                    {
                        try
                        {
                            foreach (var item in propVal as ECDArrayValue)
                            {
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }


                    try
                    {
                        object value = "ERROR";
                        propVal.TryGetNativeValue(out value);

                        bldr.AppendLine(string.Format(
                                            "\tProp: <{0}>, Type=<{1}>, StringValue=<{2}>",
                                            propVal.Property.Name, propVal.Type, value.ToString()));
                    }
                    catch (Exception)
                    {
                    }
                }
                bldr.AppendLine();
            }
        }