Пример #1
0
        private void ExportAttributeSetsAsync(MixCmsContext context, IDbContextTransaction transaction)
        {
            foreach (var item in AttributeSets)
            {
                item.Fields = MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(a => a.AttributeSetId == item.Id, context, transaction).Data?.OrderBy(a => a.Priority).ToList();
                // Filter list reference field => Add to Export Data if not exist
                var refFields = item.Fields.Where(f => f.DataType == MixDataType.Reference);

                foreach (var field in refFields)
                {
                    var refSet = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                    if (refSet == null)
                    {
                        var getSet = MixAttributeSets.ImportViewModel.Repository.GetSingleModel(m => m.Name == field.AttributeSetName, context, transaction);
                        if (getSet.IsSucceed)
                        {
                            refSet = getSet.Data;
                            refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                            AttributeSets.Add(refSet);
                        }
                    }
                    else
                    {
                        refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                    }
                }
                // Load export data if checked and did not process
                if (item.IsExportData && item.Data != null)
                {
                }
            }
        }
Пример #2
0
        public IList <CfgMessage> EliminateFirstFirstConflicts()
        {
            var result = new List <CfgMessage>();

            foreach (var nt in new List <string>(_EnumNonTerminals()))
            {
                var rules  = FillNonTerminalRules(nt);
                var rights = new List <IList <string> >();
                foreach (var rule in rules)
                {
                    rights.Add(rule.Right);
                }
                while (true)
                {
                    var pfx = rights.GetLongestCommonPrefix();
                    if (pfx.IsNullOrEmpty())
                    {
                        break;
                    }
                    // obv first first conflict
                    var nnt = GetTransformId(nt);

                    var suffixes = new List <IList <string> >();
                    foreach (var rule in rules)
                    {
                        if (rule.Right.StartsWith(pfx))
                        {
                            rights.Remove(rule.Right);
                            suffixes.Add(new List <string>(rule.Right.SubRange(pfx.Count)));
                            result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Removing rule {0} because it is part of a first-first conflict.", rule)));
                            Rules.Remove(rule);
                        }
                    }

                    var newRule = new CfgRule(nt);
                    newRule.Right.AddRange(pfx);
                    newRule.Right.Add(nnt);
                    result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Adding rule {0} to resolve first-first conflict.", newRule)));
                    if (!Rules.Contains(newRule))
                    {
                        Rules.Add(newRule);
                    }
                    foreach (var suffix in suffixes)
                    {
                        newRule = new CfgRule(nnt);
                        newRule.Right.AddRange(suffix);
                        result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Adding rule {0} to resolve first-first conflict.", newRule)));
                        if (!Rules.Contains(newRule))
                        {
                            Rules.Add(newRule);
                        }
                    }
                    var attrs = new Dictionary <string, object>();
                    attrs.Add("collapse", true);
                    AttributeSets.Add(nnt, attrs);
                }
            }
            return(result);
        }
Пример #3
0
 public AttributeSet AttribSetAdd(SketchPoint ob, string nameAttSet)
 {
     attSets = ob.AttributeSets;
     if (attSets.NameIsUsed[nameAttSet])
     {
         AttribDelete(nameAttSet);
     }
     attSet = attSets.Add(nameAttSet);
     return(attSet);
 }
Пример #4
0
 public void AttribAdd <T>(string name, T val, ValueTypeEnum VT)
 {
     attSets = doc.AttributeSets;
     if (attSets.NameIsUsed[name])
     {
         AttribDelete(name);
     }
     attSet = attSets.Add(name); attSet.Add(name, VT, val);
     attSet = null;
 }
Пример #5
0
        public void AttribAdd <T, TVal>(T ob, string name, TVal val, ValueTypeEnum VT)
        {
            AttributeSets attSets = InvDoc.Reflect.getProp <T, AttributeSets>(ob, "AttributeSets");

            if (attSets.NameIsUsed[name])
            {
                AttribDelete(name);
            }
            attSet = attSets.Add(name); attSet.Add(name, VT, val);
            attSet = null;
        }
Пример #6
0
        public IList <CfgMessage> EliminateLeftRecursion()
        {
            var result = new List <CfgMessage>();
            var ic     = Rules.Count;

            for (var i = 0; i < ic; ++i)
            {
                var rule = Rules[i];
                if (rule.IsDirectlyLeftRecursive)
                {
                    result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Removing rule {0} because it is directly left recursive.", rule)));
                    Rules.Remove(rule);
                    var newId = GetTransformId(rule.Left);

                    var col = new List <string>();
                    var c   = rule.Right.Count;
                    for (var j = 1; j < c; ++j)
                    {
                        col.Add(rule.Right[j]);
                    }
                    col.Add(newId);
                    var d = new Dictionary <string, object>();
                    AttributeSets.Add(newId, d);
                    d.Add("collapse", true);
                    var newRule = new CfgRule(newId);
                    newRule.Right.AddRange(col);
                    result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Adding rule {1} to replace rule {0}", rule, newRule)));
                    if (!Rules.Contains(newRule))
                    {
                        Rules.Add(newRule);
                    }
                    var rr = new CfgRule(newId);
                    result.Add(new CfgMessage(CfgErrorLevel.Message, -1, string.Format("Adding rule {1} to replace rule {0}", rule, rr)));
                    if (!Rules.Contains(rr))
                    {
                        Rules.Add(rr);
                    }
                    foreach (var r in Rules)
                    {
                        if (Equals(r.Left, rule.Left))
                        {
                            if (!r.IsDirectlyLeftRecursive)
                            {
                                r.Right.Add(newId);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #7
0
        public AttributeSet AttribSetAdd(object ob, string nameAttSet)
        {
            PartFeature pf;

            if (ob is PartFeature)
            {
                pf      = ob as PartFeature;
                attSets = pf.AttributeSets;
                if (attSets.NameIsUsed[nameAttSet])
                {
                    AttribDelete(nameAttSet);
                }
                attSet = attSets.Add(nameAttSet);
                return(attSet);
            }
            return(null);
        }
Пример #8
0
        private void ProcessAttributeSetsAsync(MixCmsContext context, IDbContextTransaction transaction)
        {
            foreach (var item in AttributeSets)
            {
                item.Fields = MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(a => a.AttributeSetId == item.Id, context, transaction).Data?.OrderBy(a => a.Priority).ToList();
                // Filter list reference field => Add to Export Data if not exist
                var refFields = item.Fields.Where(f => f.DataType == MixEnums.MixDataType.Reference);

                foreach (var field in refFields)
                {
                    var refSet = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                    if (refSet == null)
                    {
                        var getSet = MixAttributeSets.ImportViewModel.Repository.GetSingleModel(m => m.Name == field.AttributeSetName, context, transaction);
                        if (getSet.IsSucceed)
                        {
                            refSet = getSet.Data;
                            // Load ref data if export parent Data
                            if (item.IsExportData)
                            {
                                var refData = MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                                    a => a.Specificulture == Specificulture && a.AttributeSetId == refSet.Id, context, transaction)
                                              .Data?.OrderBy(a => a.Priority).ToList();
                                if (refData != null)
                                {
                                    AttributeSetDatas.AddRange(refData);
                                }
                            }
                            AttributeSets.Add(getSet.Data);
                        }
                    }
                    else
                    {
                        refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                        if (item.IsExportData)
                        {
                            refSet.Data = refSet.Data ?? MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                                a => a.Specificulture == Specificulture && a.AttributeSetId == refSet.Id, context, transaction)
                                          .Data?.OrderBy(a => a.Priority).ToList();
                        }
                    }
                }
                // Load export data if checked and did not process
                if (item.IsExportData)
                {
                    var data = item.Data ?? MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                        a => a.Specificulture == Specificulture && a.AttributeSetId == item.Id, context, transaction)
                               .Data?.OrderBy(a => a.Priority).ToList();
                    if (data != null)
                    {
                        AttributeSetDatas.AddRange(data);
                    }
                    foreach (var d in item.Data)
                    {
                        var getRelatedData = MixRelatedAttributeDatas.ReadViewModel.Repository.GetModelListBy(
                            m => m.ParentId == d.Id && d.Specificulture == Specificulture);
                        if (getRelatedData.IsSucceed)
                        {
                            RelatedData.AddRange(getRelatedData.Data);
                        }
                    }
                }
            }
        }
Пример #9
0
        public void AddOrRemoveFromGroup(bool add)
        {
            if (_invApp.Documents.Count == 0)
            {
                MessageBox.Show("Need to open an Assembly document");
                return;
            }

            if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject)
            {
                MessageBox.Show("Need to have an Assembly document active");
                return;
            }

            AssemblyDocument asmDoc = default(AssemblyDocument);

            asmDoc = (AssemblyDocument)_invApp.ActiveDocument;

            if (asmDoc.SelectSet.Count == 0)
            {
                MessageBox.Show("Need to select a Part or Sub Assembly");
                return;
            }

            SelectSet selSet = default(SelectSet);

            selSet = asmDoc.SelectSet;
            Inventor.Assets colour = asmDoc.Assets;
            try
            {
                ComponentOccurrence compOcc = default(ComponentOccurrence);
                object obj = null;
                foreach (object obj_loopVariable in selSet)
                {
                    obj     = obj_loopVariable;
                    compOcc = (ComponentOccurrence)obj;
                    System.Diagnostics.Debug.Print(compOcc.Name);

                    AttributeSets attbSets = compOcc.AttributeSets;

                    if (add)
                    {
                        // Add the attributes to the ComponentOccurrence

                        if (!attbSets.NameIsUsed["myPartGroup"])
                        {
                            AttributeSet attbSet = attbSets.Add("myPartGroup");

                            Inventor.Attribute attb  = attbSet.Add("PartGroup1", ValueTypeEnum.kStringType, "Group1");
                            Inventor.Asset     asset = asmDoc.Assets["Red"];
                            compOcc.Appearance = asset;
                        }
                    }
                    else
                    {
                        // Delete the attributes to the ComponentOccurrence
                        if (attbSets.NameIsUsed["myPartGroup"])
                        {
                            attbSets["myPartGroup"].Delete();
                        }
                    }

                    //compOcc.Visible = False
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Is the selected item a Component?");
                MessageBox.Show(ex.ToString());
                return;
            }
        }