private void AssertFileContains(StepRepresentationItem item, string expected)
        {
            var file = new StepFile();

            file.Items.Add(item);
            AssertFileContains(file, expected);
        }
Exemple #2
0
 private void WriteGroup(StepRepresentationItem item)
 {
     if (item.ItemType == StepItemType.ProductDefinition)
     {
         ((StepProductDefinition)item).WriteXMLGroup(_xmlWriter);
     }
 }
Exemple #3
0
        /// <summary>
        /// SetShapRelationShip
        /// </summary>
        /// <param name="item1"></param>
        /// <param name="itemType"></param>
        public List <StepRepresentationItem> GetItemsRelationShip(StepRepresentationItem item1, StepRepresentationItem item2)
        {
            List <StepRepresentationItem> relatedItems = new List <StepRepresentationItem>();

            foreach (var refObj2 in item2.RefChildItems)
            {
                if (refObj2.Value != null && refObj2.Value.Count > 0)
                {
                    foreach (var refItem2 in refObj2.Value)
                    {
                        foreach (var refObj1 in item1.RefChildItems)
                        {
                            if (refObj1.Value != null && refObj1.Value.Count > 0)
                            {
                                foreach (var refItem1 in refObj1.Value)
                                {
                                    if (refItem1 == refItem2)
                                    {
                                        relatedItems.Add(refItem1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(relatedItems);
        }
Exemple #4
0
        /// <summary>
        /// UpdateBindStyleItems
        /// </summary>
        /// <param name="item"></param>
        /// <param name="stepStyleItems"></param>
        public void UpdateBindStyleItems(StepRepresentationItem item, List <StepRepresentationItem> stepStyleItems)
        {
            List <StepRepresentationItem> bindStyleItems = new List <StepRepresentationItem>();

            foreach (var obj in item.RefChildItems)
            {
                if (obj.Value != null && obj.Value.Count > 0)
                {
                    foreach (var stepItem in stepStyleItems)
                    {
                        foreach (var objStepItem in stepItem.RefChildItems)
                        {
                            if (objStepItem.Value != null && objStepItem.Value.Count > 0)
                            {
                                foreach (var iStepItem in objStepItem.Value)
                                {
                                    if (obj.Value.Find(x => ((StepRepresentationItem)x).Id == ((StepRepresentationItem)iStepItem).Id) != null)
                                    {
                                        bindStyleItems.Add(stepItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (bindStyleItems.Count > 0)
            {
                foreach (var stepItem in bindStyleItems)
                {
                    item.AddRefObjs(stepItem);
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// SetShapRelationShip
 /// </summary>
 /// <param name="inputItem"></param>
 /// <param name="itemType"></param>
 public void SetShapRelationShip(StepRepresentationItem inputItem, StepItemType itemType)
 {
     foreach (var eachItem in _file.Items)
     {
         if (inputItem == eachItem)
         {
             continue;
         }
         if (eachItem.GetStepItemTypeStr() == itemType.ToString())
         {
             List <StepRepresentationItem> relatedItems = GetItemsRelationShip(inputItem, eachItem);
             if (relatedItems.Count > 0)
             {
                 foreach (var refObj in eachItem.RefChildItems)
                 {
                     if (refObj.Value != null && refObj.Value.Count > 0)
                     {
                         foreach (var refItem in refObj.Value)
                         {
                             if (relatedItems.Find(x => x == refItem) == null)
                             {
                                 inputItem.AddRefObjs((StepRepresentationItem)refItem);
                                 inputItem.ContainCrossRef = true; //Contains cross ref item
                                 refItem.IsCrossRef        = true;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #6
0
 /// <summary>
 /// AddRelatedItems
 /// </summary>
 /// <param name="item"></param>
 private void AddRelatedItems(StepRepresentationItem item)
 {
     if (_relatedItems.Find(x => x.Id == item.Id) == null)
     {
         _relatedItems.Add(item);
     }
 }
Exemple #7
0
 /// <summary>
 /// SetRelationShip
 /// </summary>
 public void SetRelationShip()
 {
     try
     {
         List <StepRepresentationItem> stepStyleItems = GetStyledItems();
         for (int idx = 0; idx < _file.Items.Count; idx++)
         {
             StepRepresentationItem item = _file.Items[idx];
             UpdateBindStyleItems(item, stepStyleItems);
             if (item.GetStepItemTypeStr() == StepItemType.ProductDefinition.ToString())
             {
                 AddRelatedItems(item);
             }
             else if (item.GetStepItemTypeStr() == StepItemType.NextAssemblyUsageOccurrence.ToString())
             {
                 ((StepNextAssemblyUsageOccrrence)item).Parent.ChildItems.Add(((StepNextAssemblyUsageOccrrence)item).Child);
                 ((StepNextAssemblyUsageOccrrence)item).Child.ParentItems.Add(((StepNextAssemblyUsageOccrrence)item).Parent);
                 AddRelatedItems(((StepNextAssemblyUsageOccrrence)item).Child);  //this is ProductDefinition item
                 AddRelatedItems(((StepNextAssemblyUsageOccrrence)item).Parent); //this is ProductDefinition item
             }
             else if (item.GetStepItemTypeStr() == StepItemType.ShapeDefinitionRepresentation.ToString())
             {
                 SetShapRelationShip(item, StepItemType.ShapeRepresentationRelationship);
             }
         }
     }
     catch (Exception ex)
     {
         LogWriter.Instance.WriteErrorLog(ex);
     }
 }
Exemple #8
0
        public StepFile ReadFile()
        {
            var fileSyntax = _lexer.LexFileSyntax();

            foreach (var headerMacro in fileSyntax.Header.Macros)
            {
                ApplyHeaderMacro(headerMacro);
            }

            var itemMap = new Dictionary <int, StepRepresentationItem>();
            var binder  = new StepBinder(itemMap);

            StepRepresentationItem.UnsupportedItemTypes.Clear();
            foreach (var itemInstance in fileSyntax.Data.ItemInstances)
            {
                if (itemMap.ContainsKey(itemInstance.Id))
                {
                    throw new StepReadException("Duplicate item instance", itemInstance.Line, itemInstance.Column);
                }

                var item = StepRepresentationItem.FromTypedParameter(binder, itemInstance.SimpleItemInstance, itemInstance.Id);
                if (item != null)
                {
                    itemMap.Add(itemInstance.Id, item);
                    _file.Items.Add(item);
                }
            }

            binder.BindRemainingValues();

            return(_file);
        }
Exemple #9
0
 private static void MarkReferencedItems(StepRepresentationItem item, HashSet <StepRepresentationItem> visitedItems, HashSet <StepRepresentationItem> referencedItems)
 {
     if (visitedItems.Add(item))
     {
         foreach (var referenced in item.GetReferencedItems())
         {
             referencedItems.Add(referenced);
             MarkReferencedItems(referenced, visitedItems, referencedItems);
         }
     }
 }
Exemple #10
0
 public StepSyntax GetItemSyntax(StepRepresentationItem item)
 {
     if (_inlineReferences)
     {
         var parameters = new StepSyntaxList(-1, -1, item.GetParameters(this));
         return(new StepSimpleItemSyntax(item.ItemType.GetItemTypeString(), parameters));
     }
     else
     {
         return(new StepEntityInstanceReferenceSyntax(_itemMap[item]));
     }
 }
Exemple #11
0
        public StepFile ReadFile()
        {
            var fileSyntax = _lexer.LexFileSyntax();

            foreach (var headerMacro in fileSyntax.Header.Macros)
            {
                ApplyHeaderMacro(headerMacro);
            }

            var itemMap = new Dictionary <int, List <StepRepresentationItem> >();
            var binder  = new StepBinder(itemMap);

            StepRepresentationItem.UnsupportedItemTypes.Clear();
            foreach (var itemInstance in fileSyntax.Data.ItemInstances)
            {
                if (itemMap.ContainsKey(itemInstance.Id))
                {
                    throw new StepReadException("Duplicate item instance", itemInstance.Line, itemInstance.Column);
                }
                List <StepRepresentationItem> items = new List <StepRepresentationItem>();
                if (itemInstance.SimpleItemInstance is StepSimpleItemSyntax)
                {
                    var item = StepRepresentationItem.FromTypedParameterToItem(binder, itemInstance.SimpleItemInstance, itemInstance.Id);
                    if (item != null)
                    {
                        items.Add(item);
                    }
                }
                else if (itemInstance.SimpleItemInstance is StepComplexItemSyntax)
                {
                    items = StepRepresentationItem.FromTypedParameterToItems(binder, itemInstance.SimpleItemInstance, itemInstance.Id);
                }
                else
                {
                    LogWriter.Instance.WriteErrorLog("Unsupported step item syntax " + itemInstance.SimpleItemInstance.GetType().Name);
                }
                if (items.Count > 0)
                {
                    itemMap.Add(itemInstance.Id, items);
                    foreach (var item in items)
                    {
                        _file.Items.Add(item);
                    }
                }
            }

            binder.BindRemainingValues();

            return(_file);
        }
Exemple #12
0
 private StepSyntax GetItemSyntax(StepRepresentationItem item, int expectedId)
 {
     if (!_itemMap.ContainsKey(item))
     {
         var parameters = new StepSyntaxList(-1, -1, item.GetParameters(this));
         var syntax     = new StepSimpleItemSyntax(item.ItemType.GetItemTypeString(), parameters);
         _itemMap.Add(item, expectedId);
         return(syntax);
     }
     else
     {
         return(GetItemSyntax(item));
     }
 }
Exemple #13
0
 public void BindRelationShip(StepRepresentationItem item, Action <StepBoundItem> bindAction)
 {
     for (int i = 0; i < _itemMap.Count; i++)
     {
         if (_itemMap[i] is StepShapeRepresentationRelationShip)
         {
             var itemInstance = (StepShapeRepresentationRelationShip)_itemMap[i];
             if (itemInstance.UsedRepresentation != null && itemInstance.UsedRepresentation.Id == item.Id)
             {
                 var boundItem = new StepBoundItem(_itemMap[itemInstance.Id]);
                 bindAction(boundItem);
             }
         }
     }
 }
Exemple #14
0
        public void BindValue(StepSyntax syntax, Action <StepBoundItem> bindAction)
        {
            if (syntax is StepSimpleItemSyntax)
            {
                var typedParameter = (StepSimpleItemSyntax)syntax;
                var item           = StepRepresentationItem.FromTypedParameterToItem(this, typedParameter, typedParameter.Id);
                var boundItem      = new StepBoundItem(item, syntax);
                bindAction(boundItem);
            }
            else if (syntax is StepEntityInstanceReferenceSyntax)
            {
                var itemInstance = (StepEntityInstanceReferenceSyntax)syntax;
                if (_itemMap.ContainsKey(itemInstance.Id))
                {
                    // pointer already defined, bind immediately
                    foreach (var item in _itemMap[itemInstance.Id])
                    {
                        var boundItem = new StepBoundItem(item, syntax);
                        bindAction(boundItem);
                    }
                }
                else
                {
                    // not already defined, save it for later
                    if (!_unboundPointers.ContainsKey(itemInstance.Id))
                    {
                        _unboundPointers.Add(itemInstance.Id, new List <Tuple <StepSyntax, Action <StepBoundItem> > >());
                    }

                    _unboundPointers[itemInstance.Id].Add(Tuple.Create(syntax, bindAction));
                }
            }
            else if (syntax is StepAutoSyntax)
            {
                bindAction(StepBoundItem.AutoItem(syntax));
            }
            else
            {
                throw new StepReadException("Unable to bind pointer, this should be unreachable", syntax.Line, syntax.Column);
            }
        }
Exemple #15
0
        private int WriteItem(StepRepresentationItem item, StringBuilder builder)
        {
            if (!_inlineReferences)
            {
                // not inlining references, need to write out entities as we see them
                foreach (var referencedItem in item.GetReferencedItems())
                {
                    if (!_itemMap.ContainsKey(referencedItem))
                    {
                        var refid = WriteItem(referencedItem, builder);
                    }
                }
            }

            var id     = ++_nextId;
            var syntax = GetItemSyntax(item, id);

            WriteToken(new StepEntityInstanceToken(id, -1, -1), builder);
            WriteToken(StepEqualsToken.Instance, builder);
            WriteTokens(syntax.GetTokens(), builder);
            WriteToken(StepSemicolonToken.Instance, builder);
            WriteNewLine(builder);
            return(id);
        }
Exemple #16
0
 public StepBoundItem(StepRepresentationItem item)
 {
     Item = item;
 }
Exemple #17
0
 public StepSyntax GetItemSyntaxOrAuto(StepRepresentationItem item)
 {
     return(item == null
         ? new StepAutoSyntax()
         : GetItemSyntax(item));
 }
Exemple #18
0
 public StepBoundItem(StepRepresentationItem item, StepSyntax creatingSyntax)
 {
     CreatingSyntax = creatingSyntax;
     Item           = item;
 }