Exemplo n.º 1
0
        internal void BeginNestedType(string typeName)
        {
            IfcType ifcType = IfcMetaData.IfcType(typeName);

            _currentInstance = new Part21Entity((IPersistIfc)Activator.CreateInstance(ifcType.Type));
            _processStack.Push(_currentInstance);
        }
Exemplo n.º 2
0
 public XbimParserState(IPersistEntity entity, ILogger logger = null)
 {
     _logger          = logger ?? XbimLogging.CreateLogger <EsentModel>();
     _currentInstance = new Part21Entity(entity);
     _processStack.Push(_currentInstance);
     _metadata = entity.Model.Metadata;
 }
Exemplo n.º 3
0
        protected override void EndEntity()
        {
            // Check if stack is empty to avoid exception
            if (0 == _processStack.Count)
            {
                Logger.LogError("Stack is empty");
                return;
            }
            var p21 = _processStack.Pop();

            //Debug.Assert(_processStack.Count == 0);
            CurrentInstance = null;
            if (p21.Entity != null)
            {
                try
                {
                    _entities.Add(p21.EntityLabel, p21.Entity);
                }
                catch (Exception ex)
                {
                    var msg = string.Format("Duplicate entity label: #{0}", p21.EntityLabel);
                    Logger?.LogError(msg, ex);
                }
            }
            // Console.WriteLine("EndEntity - " + CurrentSemanticValue.strVal);
        }
Exemplo n.º 4
0
 public XbimParserState(IPersistEntity entity, ILogger logger = null)
 {
     _currentInstance = new Part21Entity(entity);
     _processStack.Push(_currentInstance);
     _logger   = logger;
     _metadata = entity.Model.Metadata;
 }
Exemplo n.º 5
0
        protected override void EndHeaderEntity()
        {
            _processStack.Pop();

            CurrentInstance = null;
            // Console.WriteLine("EndHeaderEntity - " + CurrentSemanticValue.strVal);
        }
Exemplo n.º 6
0
        protected override void NewEntity(string entityLabel)
        {
            CurrentInstance = new Part21Entity(entityLabel);
            // Console.WriteLine(CurrentSemanticValue.strVal);
            _processStack.Push(CurrentInstance);
            if (_streamSize == -1 || ProgressStatus == null)
            {
                return;
            }

            var    sc            = (Scanner)Scanner;
            double pos           = sc.Buffer.Pos;
            var    newPercentage = Convert.ToInt32(pos / _streamSize * 100.0);

            if (newPercentage <= _percentageParsed)
            {
                return;
            }
            _percentageParsed = newPercentage;
            ProgressStatus(_percentageParsed, "Parsing");
            if (Cancel)
            {
                YYAccept();
            }
        }
Exemplo n.º 7
0
        protected void EndEntity()
        {
            var p21 = _processStack.Pop();

            //Debug.Assert(_processStack.Count == 0);
            CurrentInstance = null;
            if (!_inHeader && p21.Entity != null)
            {
                try
                {
                    Entities.Add(p21.EntityLabel, p21.Entity);
                }
                catch (ArgumentException)
                {
                    var exist     = Entities[p21.EntityLabel];
                    var existType = exist.GetType().Name.ToUpperInvariant();
                    var duplType  = p21.Entity.GetType().Name.ToUpperInvariant();
                    if (!string.Equals(existType, duplType, StringComparison.Ordinal))
                    {
                        Logger?.LogError(LogEventIds.FailedEntity, $"Duplicate entity label #{p21.EntityLabel} with different types: ({existType}/{duplType})");
                        ErrorCount++;
                    }
                    else
                    {
                        Logger?.LogWarning(LogEventIds.FailedEntity, $"Duplicate entity label #{p21.EntityLabel}={existType}");
                    }
                }
            }
        }
Exemplo n.º 8
0
        protected override void NewEntity(string entityLabel)
        {
            _currentInstance = new Part21Entity(entityLabel);
            _processStack.Push(_currentInstance);
            _entityCount++;
            _indexKeyValues.Clear();
            _currentLabel = Convert.ToInt32(entityLabel.TrimStart('#'));
            var data = _binaryWriter.BaseStream as MemoryStream;

            if (data != null)
            {
                data.SetLength(0);
            }


            if (_streamSize == -1 || ProgressStatus == null)
            {
                return;
            }

            var    sc            = (Scanner)Scanner;
            double pos           = sc.Buffer.Pos;
            var    newPercentage = Convert.ToInt32(pos / _streamSize * 100.0);

            if (newPercentage <= _percentageParsed)
            {
                return;
            }

            _percentageParsed = newPercentage;
            ProgressStatus(_percentageParsed, "Parsing");
        }
Exemplo n.º 9
0
 protected override void SetType(string entityTypeName)
 {
     if (InHeader)
     {
         int[] reqParams;
         // instantiates an empty IPersist from the header information
         var t = EntityCreate(entityTypeName, null, InHeader, out reqParams);
         // then attaches it to a new Part21Entity, this will be processed later from the _processStack
         // to debug value initialisation place a breakpoint on the Parse() function of
         // StepFileName, StepFileSchema or StepFileDescription classes.
         CurrentInstance = new Part21Entity(t)
         {
             RequiredParameters = reqParams
         };
         if (CurrentInstance != null)
         {
             _processStack.Push(CurrentInstance);
         }
     }
     else
     {
         var   p21 = _processStack.Peek();
         int[] reqProps;
         p21.Entity             = EntityCreate(entityTypeName, p21.EntityLabel, InHeader, out reqProps);
         p21.RequiredParameters = reqProps;
     }
     if (Cancel)
     {
         YYAccept();
     }
 }
Exemplo n.º 10
0
        internal void BeginNestedType(string typeName)
        {
            var type = _metadata.ExpressType(typeName);

            _currentInstance = new Part21Entity((IPersist)Activator.CreateInstance(type.Type));
            _processStack.Push(_currentInstance);
        }
Exemplo n.º 11
0
        public void EndList()
        {
            _listNestLevel--;
            Part21Entity p21 = _processStack.Peek();

            p21.CurrentParamIndex++;
            //Console.WriteLine("EndList");
        }
Exemplo n.º 12
0
 internal void EndNestedType()
 {
     _propertyValue.Init(_processStack.Pop().Entity);
     _currentInstance = _processStack.Peek();
     if (_currentInstance.Entity != null)
         _currentInstance.ParameterSetter(_currentInstance.CurrentParamIndex, _propertyValue);
     if (_listNestLevel == 0) _currentInstance.CurrentParamIndex++;
 }
Exemplo n.º 13
0
 protected void BeginNestedType(string value)
 {
     if (EntityCreate != null)
     {
         CurrentInstance = new Part21Entity(EntityCreate(value, null, _inHeader));
     }
     _processStack.Push(CurrentInstance);
     _isInNestedType = true;
 }
Exemplo n.º 14
0
        public void BeginList()
        {
            Part21Entity p21 = _processStack.Peek();

            if (p21.CurrentParamIndex == -1)
            {
                p21.CurrentParamIndex++; //first time in take the first argument
            }
            _listNestLevel++;
        }
Exemplo n.º 15
0
 protected override void BeginNestedType(string value)
 {
     if (EntityCreate != null)
     {
         CurrentInstance = new Part21Entity(EntityCreate(value, null, InHeader, out int[] reqProps));
     }
     _processStack.Push(CurrentInstance);
     if (Cancel)
     {
         YYAccept();
     }
 }
Exemplo n.º 16
0
 internal void EndNestedType()
 {
     _propertyValue.Init(_processStack.Pop().Entity);
     _currentInstance = _processStack.Peek();
     if (_currentInstance.Entity != null)
     {
         _currentInstance.ParameterSetter(_currentInstance.CurrentParamIndex, _propertyValue);
     }
     if (_listNestLevel == 0)
     {
         _currentInstance.CurrentParamIndex++;
     }
 }
Exemplo n.º 17
0
        protected override void EndEntity()
        {
            var p21 = _processStack.Pop();

            //Debug.Assert(_processStack.Count == 0);
            CurrentInstance = null;
            if (p21.Entity != null)
            {
                _entities.Add(p21.EntityLabel, p21.Entity);
            }


            // Console.WriteLine("EndEntity - " + CurrentSemanticValue.strVal);
        }
Exemplo n.º 18
0
        protected void EndEntity()
        {
            var p21 = _processStack.Pop();

            //Debug.Assert(_processStack.Count == 0);
            CurrentInstance = null;
            if (!_inHeader && p21.Entity != null)
            {
                try
                {
                    _entities.Add(p21.EntityLabel, p21.Entity);
                }
                catch (Exception)
                {
                    Logger?.LogError(LogEventIds.FailedEntity, $"Duplicate entity label: #{p21.EntityLabel}");
                    ErrorCount++;
                }
            }
        }
Exemplo n.º 19
0
        protected override void EndEntity()
        {
            var p21 = _processStack.Pop();

            Debug.Assert(_processStack.Count == 0);
            _currentInstance = null;
            if (_currentType != null)
            {
                _binaryWriter.Write((byte)P21ParseAction.EndEntity);
                var type  = _modelCache.Model.Metadata.ExpressType(_currentType);
                var data  = _binaryWriter.BaseStream as MemoryStream;
                var bytes = data.ToArray();
                var keys  = new List <int>(_indexKeyValues);
                _toStore.Add(new Tuple <int, short, List <int>, byte[], bool>(_currentLabel, type.TypeId, keys, bytes, type.IndexedClass));
                if (this._modelCache.IsCaching)
                {
                    _toProcess.Add(new Tuple <int, Type, byte[]>(_currentLabel, type.Type, bytes));
                }
            }
        }
Exemplo n.º 20
0
 protected bool SetType(string entityTypeName)
 {
     try
     {
         if (_inHeader)
         {
             // instantiates an empty IPersist from the header information
             var t = EntityCreate(entityTypeName, null, _inHeader);
             // then attaches it to a new Part21Entity, this will be processed later from the _processStack
             // to debug value initialisation place a breakpoint on the Parse() function of
             // StepFileName, StepFileSchema or StepFileDescription classes.
             CurrentInstance = new Part21Entity(t);
             if (CurrentInstance != null)
             {
                 _processStack.Push(CurrentInstance);
             }
         }
         else
         {
             if (ListNestLevel == -1)
             {
                 var p21 = _processStack.Peek();
                 p21.Entity = EntityCreate(entityTypeName, p21.EntityLabel, _inHeader);
             }
             else
             {
                 BeginNestedType(entityTypeName);
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         if (_errors.AddTypeNotCreated(entityTypeName))
         {
             Logger?.LogError(LogEventIds.FailedEntity, e, $"Could not create type {entityTypeName}");
             ErrorCount++;
         }
         return(false);
     }
 }
Exemplo n.º 21
0
        private void NewEntity(int entityLabel)
        {
            CurrentInstance = new Part21Entity(entityLabel);
            // Console.WriteLine(CurrentSemanticValue.strVal);
            _processStack.Push(CurrentInstance);
            if (_streamSize < 0 || _progressStatus == null)
            {
                return;
            }

            if (_reportEntityCount++ < 500)
            {
                return;
            }

            double pos        = _scanner.Buffer.Pos;
            var    percentage = Convert.ToInt32(pos / _streamSize * 100.0);

            _reportEntityCount = 0;
            _progressStatus?.Invoke(percentage, "Parsing");
        }
Exemplo n.º 22
0
        protected void EndNestedType()
        {
            _isInNestedType = false;
            try
            {
                PropertyValue.Init(_processStack.Pop().Entity);
                CurrentInstance = _processStack.Peek();
                if (CurrentInstance.Entity != null)
                {
                    CurrentInstance.Entity.Parse(CurrentInstance.CurrentParamIndex, PropertyValue, NestedIndex);
                }
            }
            catch (Exception e)
            {
                // return silently if this kind of error has already been reported
                if (!_errors.AddPropertyNotSet(CurrentInstance.Entity, CurrentInstance.CurrentParamIndex, PropertyValue, e))
                {
                    return;
                }

                var mainEntity = _processStack.Last();
                if (mainEntity != null)
                {
                    Logger?.LogError(LogEventIds.FailedEntity, e, "Entity #{0,-5} {1}, error at parameter {2}",
                                     mainEntity.EntityLabel, mainEntity.Entity.GetType().Name.ToUpper(),
                                     mainEntity.CurrentParamIndex + 1
                                     );
                }
                else
                {
                    Logger?.LogError(LogEventIds.FailedEntity, e, "Unhandled Parser error, in Parser.cs EndNestedType");
                }
                ErrorCount++;
            }
            if (ListNestLevel == 0)
            {
                CurrentInstance.CurrentParamIndex++;
                _deferListItems = false;
            }
        }
Exemplo n.º 23
0
 protected override void EndNestedType(string value)
 {
     try
     {
         PropertyValue.Init(_processStack.Pop().Entity);
         CurrentInstance = _processStack.Peek();
         if (CurrentInstance.Entity != null)
         {
             CurrentInstance.ParameterSetter(CurrentInstance.CurrentParamIndex, PropertyValue, NestedIndex);
         }
     }
     catch (Exception)
     {
         if (ErrorCount > MaxErrorCount)
         {
             throw new XbimParserException("Too many errors in file, parser execution terminated");
         }
         ErrorCount++;
         var mainEntity = _processStack.Last();
         if (mainEntity != null)
         {
             var expressType = Metadata.ExpressType(mainEntity.Entity);
             Logger.ErrorFormat("Entity #{0,-5} {1}, error at parameter {2}-{3} value = {4}",
                                mainEntity.EntityLabel, mainEntity.Entity.GetType().Name.ToUpper(),
                                mainEntity.CurrentParamIndex + 1,
                                expressType.Properties[mainEntity.CurrentParamIndex + 1].PropertyInfo.Name,
                                value);
         }
         else
         {
             Logger.Error("Unhandled Parser error, in Parser.cs EndNestedType");
         }
     }
     if (ListNestLevel == 0)
     {
         CurrentInstance.CurrentParamIndex++;
         _deferListItems = false;
     }
 }
Exemplo n.º 24
0
        protected override void SetType(string entityTypeName)
        {
            if (InHeader)
            {
                IPersist currentHeaderEntity;
                switch (entityTypeName)
                {
                case "FILE_DESCRIPTION":
                    currentHeaderEntity = _header.FileDescription;
                    break;

                case "FILE_NAME":
                    currentHeaderEntity = _header.FileName;
                    break;

                case "FILE_SCHEMA":
                    currentHeaderEntity = _header.FileSchema;
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid Header entity type {0}", entityTypeName));
                }
                _currentInstance = new Part21Entity(currentHeaderEntity);
                _processStack.Push(_currentInstance);
            }
            else
            {
                _currentType = entityTypeName;
                var type = _modelCache.Model.Metadata.ExpressType(_currentType);
                if (type == null)
                {
                    throw new ArgumentException(string.Format("Invalid entity type {0}", _currentType));
                }
                _indexKeys = type.IndexedValues;
            }
        }
Exemplo n.º 25
0
        internal override void SetType(string entityTypeName)
        {
            if (InHeader)
            {
                IPersistIfc currentHeaderEntity;
                switch (entityTypeName)
                {
                    case "FILE_DESCRIPTION":
                        currentHeaderEntity = _header.FileDescription;
                        break;
                    case "FILE_NAME":
                        currentHeaderEntity = _header.FileName;
                        break;
                    case "FILE_SCHEMA":
                        currentHeaderEntity = _header.FileSchema;
                        break;
                    default:
                        throw new ArgumentException(string.Format("Invalid Header entity type {0}", entityTypeName));
                }
                _currentInstance = new Part21Entity(currentHeaderEntity);
                _processStack.Push(_currentInstance);
            }
            else
            {

                _currentType = entityTypeName;
                IfcType ifcType = IfcMetaData.IfcType(_currentType);
                _indexKeys = ifcType.IndexedValues;
            }
        }
Exemplo n.º 26
0
 internal override void NewEntity(string entityLabel)
 {
     _currentInstance = new Part21Entity(entityLabel);
     // Console.WriteLine(CurrentSemanticValue.strVal);
     _processStack.Push(_currentInstance);
     if (_streamSize != -1 && ProgressStatus != null)
     {
         Scanner sc = (Scanner) this.Scanner;
         double pos = sc.Buffer.Pos;
         int newPercentage = Convert.ToInt32(pos/_streamSize*100.0);
         if (newPercentage > _percentageParsed)
         {
             _percentageParsed = newPercentage;
             ProgressStatus(_percentageParsed, "Parsing");
         }
     }
 }
Exemplo n.º 27
0
 internal override void EndNestedType(string value)
 {
     try
     {
         _propertyValue.Init(_processStack.Pop().Entity);
         _currentInstance = _processStack.Peek();
         if (_currentInstance.Entity != null)
             _currentInstance.ParameterSetter(_currentInstance.CurrentParamIndex, _propertyValue);
     }
     catch (Exception )
     {
         if (_errorCount > MaxErrorCount)
             throw new Exception("Too many errors in file, parser execution terminated");
         _errorCount++;
         Part21Entity mainEntity = _processStack.Last();
         if (mainEntity != null)
         {
             IfcType ifcType = IfcMetaData.IfcType(mainEntity.Entity);
             Logger.ErrorFormat("Entity #{0,-5} {1}, error at parameter {2}-{3} value = {4}",
                                        mainEntity.EntityLabel, mainEntity.Entity.GetType().Name.ToUpper(),
                                        mainEntity.CurrentParamIndex + 1,
                                        ifcType.IfcProperties[mainEntity.CurrentParamIndex + 1].PropertyInfo.Name,
                                        value);
         }
         else
         {
             Logger.Error("Unhandled Parser error, in Parser.cs EndNestedType");
         }
     }
     if (_listNestLevel == 0)
     {
         _currentInstance.CurrentParamIndex++;
         _deferListItems = false;
     }
 }
Exemplo n.º 28
0
        internal override void EndEntity()
        {
            Part21Entity p21 = _processStack.Pop();
            //Debug.Assert(_processStack.Count == 0);
            _currentInstance = null;
            if (p21.Entity != null)
                _entities.Add(p21.EntityLabel, p21.Entity);


            // Console.WriteLine("EndEntity - " + CurrentSemanticValue.strVal);
        }
Exemplo n.º 29
0
        internal override void EndHeaderEntity()
        {
            _processStack.Pop();

            _currentInstance = null;
            // Console.WriteLine("EndHeaderEntity - " + CurrentSemanticValue.strVal);
        }
Exemplo n.º 30
0
        internal override void SetType(string entityTypeName)
        {
            Scanner sc = (Scanner) this.Scanner;

            if (InHeader)
            {
                int[] reqParams;
                _currentInstance = new Part21Entity(EntityCreate(entityTypeName, null, InHeader, out reqParams));
                _currentInstance.RequiredParameters = reqParams;
                _processStack.Push(_currentInstance);
            }
            else
            {
                Part21Entity p21 = _processStack.Peek();
                int[] reqProps;
                p21.Entity = EntityCreate(entityTypeName, p21.EntityLabel, InHeader, out reqProps);
                p21.RequiredParameters = reqProps;
            }
        }
Exemplo n.º 31
0
 internal override void BeginNestedType(string value)
 {
     int[] reqProps;
     _currentInstance = new Part21Entity(EntityCreate(value, null, InHeader, out reqProps));
     _currentInstance.RequiredParameters = reqProps;
     _processStack.Push(_currentInstance);
 }
Exemplo n.º 32
0
 internal override void EndEntity()
 {
     Part21Entity p21 = _processStack.Pop();
     Debug.Assert(_processStack.Count == 0);
     _currentInstance = null;
     if (_currentType != null)
     {
         _binaryWriter.Write((byte)P21ParseAction.EndEntity);
         IfcType ifcType = IfcMetaData.IfcType(_currentType);
         MemoryStream data = _binaryWriter.BaseStream as MemoryStream;
         byte[] bytes =  data.ToArray();
         List<int> keys = new List<int>(_indexKeyValues);
         toStore.Add(new Tuple<int, short, List<int>, byte[], bool>(_currentLabel, ifcType.TypeId, keys, bytes, ifcType.IndexedClass));
         if (this.modelCache.IsCaching) toProcess.Add(new Tuple<int, Type, byte[]>(_currentLabel, ifcType.Type, bytes));
     }
 }
Exemplo n.º 33
0
 internal override void EndHeaderEntity()
 {
     _processStack.Pop();
     _currentInstance = null;
 }
Exemplo n.º 34
0
        internal override void NewEntity(string entityLabel)
        {
            _currentInstance = new Part21Entity(entityLabel);
            _processStack.Push(_currentInstance);
            _entityCount++;
            _indexKeyValues.Clear();
            _currentLabel = Convert.ToInt32(entityLabel.TrimStart('#'));
            MemoryStream data = _binaryWriter.BaseStream as MemoryStream;
            data.SetLength(0);

            if (_streamSize != -1 && ProgressStatus != null)
            {
                Scanner sc = (Scanner)this.Scanner;
                double pos = sc.Buffer.Pos;
                int newPercentage = Convert.ToInt32(pos / _streamSize * 100.0);
                if (newPercentage > _percentageParsed)
                {
                    _percentageParsed = newPercentage;
                    ProgressStatus(_percentageParsed, "Parsing");
                }
            }
        }
Exemplo n.º 35
0
 public XbimParserState(IPersistIfcEntity entity)
 {
     _currentInstance = new Part21Entity(entity);
     _processStack.Push(_currentInstance);
 }
Exemplo n.º 36
0
 internal void BeginNestedType(string typeName)
 {
     IfcType ifcType = IfcMetaData.IfcType(typeName);
     _currentInstance = new Part21Entity((IPersistIfc)Activator.CreateInstance(ifcType.Type));
     _processStack.Push(_currentInstance);
 }
Exemplo n.º 37
0
 protected override void EndHeaderEntity()
 {
     _processStack.Pop();
     _currentInstance = null;
 }
Exemplo n.º 38
0
 public XbimParserState(IPersistIfcEntity entity)
 {
     _currentInstance = new Part21Entity(entity);
     _processStack.Push(_currentInstance);
 }