Ejemplo n.º 1
0
        internal int AddDirectoryAndParameterLines(WriterState writerState)
        {
            OnBeforeWrite();
            writerState.ReportReferencedEntities(GetReferencedEntities());

            // write structure entity (field 3)
            if (StructureEntity != null)
            {
                _structurePointer = -writerState.GetOrWriteEntityIndex(StructureEntity);
            }
            else
            {
                _structurePointer = 0;
            }

            // write line font pattern (field 4)
            int lineFontPattern = 0;

            if (CustomLineFont != null)
            {
                lineFontPattern = -writerState.GetOrWriteEntityIndex(CustomLineFont);
            }
            else
            {
                lineFontPattern = (int)LineFont;
            }

            // write levels (field 5)
            if (Levels.Count <= 1)
            {
                _levelsPointer = Levels.FirstOrDefault();
            }
            else
            {
                _levelsPointer = -writerState.GetLevelsPointer(Levels);
            }

            // write view (field 6)
            if (View != null)
            {
                _viewPointer = writerState.GetOrWriteEntityIndex(View);
            }
            else
            {
                _viewPointer = 0;
            }

            // write transformation matrix (field 7)
            if (TransformationMatrix != null && !TransformationMatrix.IsIdentity)
            {
                _transformationMatrixPointer = writerState.GetOrWriteEntityIndex(TransformationMatrix);
            }
            else
            {
                _transformationMatrixPointer = 0;
            }

            // write label display associativity (field 8)
            if (LabelDisplay != null)
            {
                _labelDisplayPointer = writerState.GetOrWriteEntityIndex(LabelDisplay);
            }
            else
            {
                _labelDisplayPointer = 0;
            }

            // write custom color entity (field 13)
            int color = 0;

            if (CustomColor != null)
            {
                color = -writerState.GetOrWriteEntityIndex(CustomColor);
            }
            else
            {
                color = (int)Color;
            }

            var parameters = new List <object>();

            parameters.Add((int)EntityType);
            this.WriteParameters(parameters, writerState.WriterBinder);

            if (AssociatedEntities.Any() || Properties.Any())
            {
                writerState.ReportReferencedEntities(AssociatedEntities);
                writerState.ReportReferencedEntities(Properties);
                parameters.Add(AssociatedEntities.Count);
                parameters.AddRange(AssociatedEntities.Select(writerState.WriterBinder.GetEntityId).Cast <object>());

                if (Properties.Any())
                {
                    parameters.Add(Properties.Count);
                    parameters.AddRange(Properties.Select(writerState.WriterBinder.GetEntityId).Cast <object>());
                }
            }

            var nextDirectoryIndex = writerState.DirectoryLines.Count + 1;
            var nextParameterIndex = writerState.ParameterLines.Count + 1;

            this._lineCount = IgesFileWriter.AddParametersToStringList(parameters.ToArray(), writerState.ParameterLines, writerState.FieldDelimiter, writerState.RecordDelimiter,
                                                                       lineSuffix: string.Format(" {0,7}", nextDirectoryIndex),
                                                                       comment: Comment);
            var dir = GetDirectoryData(color, lineFontPattern);

            dir.ParameterPointer = nextParameterIndex;
            dir.ToString(writerState.DirectoryLines);

            writerState.EntityMap[this] = nextDirectoryIndex;

            return(nextDirectoryIndex);
        }