示例#1
0
文件: OcadExport.cs 项目: jonc/carto
        void WriteLineSymDef(LineSymDef symdef)
        {
            OcadLineSymbol symbol = new OcadLineSymbol();
            FillInCommonSymdef(symbol, symdef);

            symbol.Otp = 2;
            symbol.SymTp = 0;
            symbol.Extent = (short) ToOcadDimensions(symdef.MaxThickness / 2);
            symbol.LineColor = symdef.LineColor != null ? (short) NumberOfColor(symdef.LineColor) : (short)0;
            symbol.LineWidth = (short) ToOcadDimensions(symdef.LineThickness);
            symbol.DistFromStart = 0;
            symbol.DistToEnd = 0;
            symbol.LineEnds = (ushort) OcadLineStyle(symdef.MainLineStyle);

            LineSymDef.GlyphInfo[] glyphs = symdef.Glyphs;
            int startGlyphIndex = -1, endGlyphIndex = -1, cornerGlyphIndex = -1;
            int dashCenteredGlyphIndex = -1, gapCenteredGlyphIndex = -1, spacedGlyphIndex = -1, spacedOffsetGlyphIndex = -1;
            int primGlyphIndex = -1, secondaryGlyphIndex = -1;

            if (glyphs != null) {
                for (int i = 0; i < glyphs.Length; ++i) {
                    // UNDONE: give warning if more than one glyph of a certain type
                    switch (glyphs[i].location) {
                    case LineSymDef.GlyphLocation.Corners:			cornerGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.DashCenters:		dashCenteredGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.MiddleDashCenters:		secondaryGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.End:				endGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.GapCenters:		gapCenteredGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.Spaced: spacedGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.SpacedDecrease: spacedGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.SpacedOffset: spacedOffsetGlyphIndex = i; break;
                    case LineSymDef.GlyphLocation.Start: startGlyphIndex = i; break;
                    }
                }
            }

            LineSymDef.DashInfo dashInfo = new LineSymDef.DashInfo();
            if (symdef.IsDashed) {
                dashInfo = symdef.Dashes;
                symbol.MainLength = (short) ToOcadDimensions(dashInfo.dashLength);
                symbol.EndLength = (short) ToOcadDimensions(dashInfo.firstDashLength);
                symbol.MainGap = (short) ToOcadDimensions(dashInfo.gapLength);
                symbol.MinSym = (short)(dashInfo.minGaps - 1);
                symbol.SecGap = (short) (dashInfo.secondaryMiddleGaps > 0 ? ToOcadDimensions(dashInfo.secondaryMiddleLength) : 0);
                symbol.EndGap = (short) (dashInfo.secondaryEndGaps > 0 ? ToOcadDimensions(dashInfo.secondaryEndLength) : 0);
            }
            else {
                symbol.MainLength = symbol.EndLength = 0;
                symbol.MainGap = symbol.SecGap = 0;
                symbol.MinSym = 0;
            }

            // The primary glyph is the one centered on gaps.
            primGlyphIndex = gapCenteredGlyphIndex;

            if (spacedGlyphIndex >= 0 && glyphs[spacedGlyphIndex].location == LineSymDef.GlyphLocation.SpacedDecrease) {
                // decreasing symbol.
                symbol.MainLength = (short) ToOcadDimensions(glyphs[spacedGlyphIndex].distance);
                symbol.EndLength = (short) ToOcadDimensions(glyphs[spacedGlyphIndex].firstDistance);
                symbol.MinSym = (short) (glyphs[spacedGlyphIndex].minimum - 1);
                symbol.DecMode = glyphs[spacedGlyphIndex].decreaseBothEnds ? (ushort)2 : (ushort)1;
                symbol.DecLast = (short) Math.Round(glyphs[spacedGlyphIndex].decreaseLimit * 100);
                primGlyphIndex = spacedGlyphIndex;
            }
            else if (spacedGlyphIndex >= 0 && (!symdef.IsDashed || symdef.LineThickness == 0)) {
                // the spaced glyph is actually the primary one, since there is no dashes.
                symbol.MainLength = (short) ToOcadDimensions(glyphs[spacedGlyphIndex].distance);
                symbol.EndLength = (short) ToOcadDimensions(glyphs[spacedGlyphIndex].firstDistance);
                symbol.MainGap = 0;
                symbol.SecGap = 0;
                symbol.MinSym = (short) (glyphs[spacedGlyphIndex].minimum - 1);
                primGlyphIndex = spacedGlyphIndex;
            }
            else if (spacedOffsetGlyphIndex >= 0 && (!symdef.IsDashed || symdef.LineThickness == 0)) {
                // the spaced offset glyph is actually the primary one, since there is no dashes.
                symbol.MainLength = (short) ToOcadDimensions(glyphs[spacedOffsetGlyphIndex].distance);
                symbol.EndLength = (short) ToOcadDimensions(glyphs[spacedOffsetGlyphIndex].firstDistance);
                symbol.MainGap = 0;
                symbol.SecGap = 0;
                symbol.MinSym = (short) (glyphs[spacedOffsetGlyphIndex].minimum - 1);
            }
            else if (dashCenteredGlyphIndex >= 0 && gapCenteredGlyphIndex == -1 && symdef.IsDashed && dashInfo.secondaryMiddleGaps == 0 && dashInfo.secondaryEndGaps == 0) {
                // Use the secondary gaps to represent the primary gaps.
                symbol.MinSym += 1;
                symbol.MainLength += symbol.MainGap;
                symbol.SecGap = symbol.MainGap;
                symbol.MainGap = 0;
                symbol.EndLength = (short) ((symbol.MainLength + 1) / 2);
                primGlyphIndex = dashCenteredGlyphIndex;
            }

            if (symdef.HasSecondLine) {
                symbol.FrColor = (short) NumberOfColor(symdef.SecondLineColor);
                symbol.FrWidth = (short) ToOcadDimensions(symdef.SecondThickness);
                symbol.FrStyle =  OcadLineStyle(symdef.SecondLineStyle);
            }

            if (symdef.IsDoubleLine) {
                LineSymDef.DoubleLineInfo doubleInfo = symdef.DoubleLines;

                symbol.DblMode = 1;  // may be changed below.
                symbol.DblWidth = (short) ToOcadDimensions(doubleInfo.doubleThick);

                if (doubleInfo.doubleFillColor != null) {
                    symbol.DblFlags |= 1;
                    symbol.DblFillColor = NumberOfColor(doubleInfo.doubleFillColor);
                }

                if (doubleInfo.doubleLeftColor != null) {
                    symbol.DblLeftColor = NumberOfColor(doubleInfo.doubleLeftColor);
                    symbol.DblLeftWidth = (short) ToOcadDimensions(doubleInfo.doubleLeftWidth);
                }
                if (doubleInfo.doubleRightColor != null) {
                    symbol.DblRightColor = NumberOfColor(doubleInfo.doubleRightColor);
                    symbol.DblRightWidth = (short) ToOcadDimensions(doubleInfo.doubleRightWidth);
                }

                if (doubleInfo.doubleLeftDashed || doubleInfo.doubleRightDashed || doubleInfo.doubleFillDashed) {
                    symbol.DblLength = (short) ToOcadDimensions(doubleInfo.doubleDashes.dashLength);
                    symbol.DblGap = (short) ToOcadDimensions(doubleInfo.doubleDashes.gapLength);

                    if (doubleInfo.doubleFillDashed)
                        symbol.DblMode = 4;
                    else if (doubleInfo.doubleRightDashed)
                        symbol.DblMode = 3;
                    else
                        symbol.DblMode = 2;
                }
            }

            if (symdef.IsShortened) {
                LineSymDef.ShortenInfo shortening = symdef.Shortening;

                symbol.DistFromStart = (short) ToOcadDimensions(shortening.shortenBeginning);
                symbol.DistToEnd = (short) ToOcadDimensions(shortening.shortenEnd);
                if (shortening.pointyEnds)
                    symbol.LineEnds |= 2;
            }

            if (primGlyphIndex >= 0) {
                LineSymDef.GlyphInfo glyph = glyphs[primGlyphIndex];
                symbol.nPrimSym = (short) glyph.number;
                symbol.PrimSymDist = (short) ToOcadDimensions(glyph.spacing);
                symbol.PrimDElts = SymbolEltsFromGlyph(glyph.glyph, out symbol.PrimDSize);
            }
            if (spacedOffsetGlyphIndex >= 0)  // UNDONE: if both secondaryGlyphIndex and spacedOffset, we can only represent one in OCAD.
                symbol.SecDElts = SymbolEltsFromGlyph(glyphs[spacedOffsetGlyphIndex].glyph, out symbol.SecDSize);
            if (secondaryGlyphIndex >= 0)
                symbol.SecDElts = SymbolEltsFromGlyph(glyphs[secondaryGlyphIndex].glyph, out symbol.SecDSize);
            if (startGlyphIndex >= 0)
                symbol.StartDElts = SymbolEltsFromGlyph(glyphs[startGlyphIndex].glyph, out symbol.StartDSize);
            if (endGlyphIndex >= 0)
                symbol.EndDElts = SymbolEltsFromGlyph(glyphs[endGlyphIndex].glyph, out symbol.EndDSize);
            if (cornerGlyphIndex >= 0)
                symbol.CornerDElts = SymbolEltsFromGlyph(glyphs[cornerGlyphIndex].glyph, out symbol.CornerDSize);

            symbol.Write(writer, version);
        }
示例#2
0
文件: OcadImport.cs 项目: jonc/carto
        SymDef CreateLineSymdef(string name, int ocadID, OcadLineSymbol ocadSym)
        {
            float width = ToWorldDimensions(ocadSym.LineWidth);

            SymColor color = null;
            if (width > 0)
                color = GetColor(ocadSym.LineColor);

            LineStyle lineStyle = ImportLineStyle((short) ocadSym.LineEnds);

            LineSymDef symdef = new LineSymDef(name, ocadID, color, width, lineStyle);

            if (ocadSym.DistFromStart != 0 || ocadSym.DistToEnd != 0) {
                LineSymDef.ShortenInfo shortenInfo;
                shortenInfo.shortenBeginning = ToWorldDimensions(ocadSym.DistFromStart);
                shortenInfo.shortenEnd = ToWorldDimensions(ocadSym.DistToEnd);
                shortenInfo.pointyEnds = ((ocadSym.LineEnds & 2) != 0);

                symdef.SetShortening(shortenInfo);
            }

            if (ocadSym.FrWidth > 0) {
                SymColor secondColor = GetColor(ocadSym.FrColor);
                float secondWidth = ToWorldDimensions(ocadSym.FrWidth);
                LineStyle secondLineStyle = ImportLineStyle(ocadSym.FrStyle);

                symdef.SetSecondLine(secondColor, secondWidth, secondLineStyle);
            }

            if (ocadSym.DblMode > 0) {
                LineSymDef.DoubleLineInfo doubleLines;
                if ((ocadSym.DblFlags & 1) != 0) {
                    doubleLines.doubleFillColor = GetColor(ocadSym.DblFillColor);
                }
                else {
                    doubleLines.doubleFillColor = null;
                }

                doubleLines.doubleLeftColor = GetColor(ocadSym.DblLeftColor);
                doubleLines.doubleRightColor = GetColor(ocadSym.DblRightColor);
                doubleLines.doubleThick = ToWorldDimensions(ocadSym.DblWidth);
                doubleLines.doubleLeftWidth = ToWorldDimensions(ocadSym.DblLeftWidth);
                doubleLines.doubleRightWidth = ToWorldDimensions(ocadSym.DblRightWidth);

                if (ocadSym.DblMode > 1) {
                    if (ocadSym.DblMode == 2) {
                        doubleLines.doubleLeftDashed = true;
                        doubleLines.doubleFillDashed = doubleLines.doubleRightDashed = false;
                    }
                    else if (ocadSym.DblMode == 3) {
                        doubleLines.doubleLeftDashed = doubleLines.doubleRightDashed = true;
                        doubleLines.doubleFillDashed = false;
                    }
                    else {
                        doubleLines.doubleFillDashed = doubleLines.doubleLeftDashed = doubleLines.doubleRightDashed = true;
                    }

                    doubleLines.doubleDashes.dashLength = doubleLines.doubleDashes.firstDashLength = doubleLines.doubleDashes.lastDashLength = ToWorldDimensions(ocadSym.DblLength);
                    doubleLines.doubleDashes.gapLength = ToWorldDimensions(ocadSym.DblGap);
                    doubleLines.doubleDashes.minGaps = 1;
                    doubleLines.doubleDashes.secondaryEndGaps = 0;
                    doubleLines.doubleDashes.secondaryEndLength = 0;
                    doubleLines.doubleDashes.secondaryMiddleGaps = 0;
                    doubleLines.doubleDashes.secondaryMiddleLength = 0;
                }
                else {
                    doubleLines.doubleFillDashed = doubleLines.doubleLeftDashed = doubleLines.doubleRightDashed = false;
                    doubleLines.doubleDashes = new LineSymDef.DashInfo();
                }
                symdef.SetDoubleLines(doubleLines);
            }

            if (ocadSym.MainGap > 0 || ocadSym.SecGap > 0) {
                LineSymDef.DashInfo dashInfo = new LineSymDef.DashInfo();

                dashInfo.dashLength = ToWorldDimensions(ocadSym.MainLength);
                dashInfo.firstDashLength = dashInfo.lastDashLength = ToWorldDimensions(ocadSym.EndLength);
                dashInfo.gapLength = ToWorldDimensions(ocadSym.MainGap);
                dashInfo.minGaps = ocadSym.MinSym + 1;

                if (ocadSym.SecGap > 0) {
                    dashInfo.secondaryMiddleGaps = 1;
                    dashInfo.secondaryMiddleLength = ToWorldDimensions(ocadSym.SecGap);
                }
                if (ocadSym.EndGap > 0) {
                    dashInfo.secondaryEndGaps = 1;
                    dashInfo.secondaryEndLength = ToWorldDimensions(ocadSym.EndGap);
                }

                symdef.SetDashInfo(dashInfo);
            }

            int numGlyphs = 0, iGlyph = 0;
            LineSymDef.GlyphInfo[] glyphs = null;

            if (ocadSym.PrimDElts != null && ocadSym.PrimDElts.Length > 0)			++numGlyphs;
            if (ocadSym.SecDElts != null && ocadSym.SecDElts.Length > 0)			++numGlyphs;
            if (ocadSym.CornerDElts != null && ocadSym.CornerDElts.Length > 0)		++numGlyphs;
            if (ocadSym.StartDElts != null && ocadSym.StartDElts.Length > 0)		++numGlyphs;
            if (ocadSym.EndDElts != null && ocadSym.EndDElts.Length > 0)			++numGlyphs;

            if (numGlyphs > 0) {
                glyphs = new LineSymDef.GlyphInfo[numGlyphs];

                if (ocadSym.PrimDElts != null && ocadSym.PrimDElts.Length > 0) {
                    LineSymDef.GlyphInfo glyphInfo = new LineSymDef.GlyphInfo();

                    glyphInfo.glyph = CreateGlyph(ocadSym.PrimDElts);
                    glyphInfo.number = ocadSym.nPrimSym;
                    glyphInfo.spacing = ToWorldDimensions(ocadSym.PrimSymDist);

                    if (ocadSym.DecMode > 0) {
                        glyphInfo.location = LineSymDef.GlyphLocation.SpacedDecrease;
                        glyphInfo.distance = ToWorldDimensions(ocadSym.MainLength + ocadSym.MainGap);
                        glyphInfo.firstDistance = glyphInfo.lastDistance = ToWorldDimensions(ocadSym.EndLength) + (ToWorldDimensions(ocadSym.MainGap) / 2);
                        glyphInfo.minimum = Math.Max(1, ocadSym.MinSym + 1);   // OCAD always does at least one symbol, even if you say zero!
                        glyphInfo.decreaseLimit = (float) ocadSym.DecLast / 100F;
                        glyphInfo.decreaseBothEnds = (ocadSym.DecMode == 2);
                    }
                    else if (width > 0 && ocadSym.MainGap > 0 || ocadSym.SecGap > 0) {
                        glyphInfo.location = LineSymDef.GlyphLocation.GapCenters;
                        glyphInfo.minimum = 1; // OCAD always does at least one symbol, even if you say zero!
                    }
                    else {
                        glyphInfo.location = LineSymDef.GlyphLocation.Spaced;
                        glyphInfo.distance = ToWorldDimensions(ocadSym.MainLength + ocadSym.MainGap);
                        glyphInfo.firstDistance = glyphInfo.lastDistance = ToWorldDimensions(ocadSym.EndLength) + (ToWorldDimensions(ocadSym.MainGap) / 2);
                        glyphInfo.minimum = Math.Max(1, ocadSym.MinSym + 1);   // OCAD always does at least one symbol, even if you say zero!
                    }

                    glyphs[iGlyph++] = glyphInfo;
                }

                if (ocadSym.SecDElts != null && ocadSym.SecDElts.Length > 0) {
                    LineSymDef.GlyphInfo glyphInfo = new LineSymDef.GlyphInfo();
                    glyphInfo.glyph = CreateGlyph(ocadSym.SecDElts);
                    glyphInfo.number = 1;
                    glyphInfo.location = LineSymDef.GlyphLocation.SpacedOffset;
                    glyphInfo.offset = ToWorldDimensions(ocadSym.MainLength) / 2;
                    glyphInfo.distance = ToWorldDimensions(ocadSym.MainLength + ocadSym.MainGap);
                    glyphInfo.firstDistance = glyphInfo.lastDistance = ToWorldDimensions(ocadSym.EndLength) + (ToWorldDimensions(ocadSym.MainGap) / 2);
                    glyphInfo.minimum = Math.Max(1, ocadSym.MinSym + 1);   // OCAD always does at least one symbol, even if you say zero!

                    glyphs[iGlyph++] = glyphInfo;
                }

                if (ocadSym.CornerDElts != null && ocadSym.CornerDElts.Length > 0) {
                    LineSymDef.GlyphInfo glyphInfo = new LineSymDef.GlyphInfo();
                    glyphInfo.glyph = CreateGlyph(ocadSym.CornerDElts);
                    glyphInfo.number = 1;
                    glyphInfo.location = LineSymDef.GlyphLocation.Corners;

                    glyphs[iGlyph++] = glyphInfo;
                }

                if (ocadSym.StartDElts != null && ocadSym.StartDElts.Length > 0) {
                    LineSymDef.GlyphInfo glyphInfo = new LineSymDef.GlyphInfo();
                    glyphInfo.glyph = CreateGlyph(ocadSym.StartDElts);
                    glyphInfo.number = 1;
                    glyphInfo.location = LineSymDef.GlyphLocation.Start;

                    glyphs[iGlyph++] = glyphInfo;
                }

                if (ocadSym.EndDElts != null && ocadSym.EndDElts.Length > 0) {
                    LineSymDef.GlyphInfo glyphInfo = new LineSymDef.GlyphInfo();
                    glyphInfo.glyph = CreateGlyph(ocadSym.EndDElts);
                    glyphInfo.number = 1;
                    glyphInfo.location = LineSymDef.GlyphLocation.End;

                    glyphs[iGlyph++] = glyphInfo;
                }

                symdef.SetGlyphs(glyphs);
            }

            return symdef;
        }
示例#3
0
		static public OcadSymbol Read(BinaryReader reader, int version) {

			int Size;
            int Sym = 0;
            short Otp;
            byte SymTp = 0;
            if (version <= 8) {
                Size = reader.ReadInt16();
                Sym = reader.ReadInt16();
                Otp = reader.ReadInt16();
                SymTp = reader.ReadByte();
            }
            else {
                Size = reader.ReadInt32();
                Sym = reader.ReadInt32();
                Otp = reader.ReadByte();
            }

			byte Flags = reader.ReadByte();
			OcadSymbol sym;

            if (Otp == 1) {
                sym = new OcadPointSymbol();
            }
            else if (Otp == 2 && SymTp == 0)
                sym = new OcadLineSymbol();
            else if (Otp == 2 && SymTp == 1)
                sym = new OcadLineTextSymbol();
            else if (Otp == 3)
                sym = new OcadAreaSymbol();
            else if (Otp == 4)
                sym = new OcadTextSymbol();
            else if (Otp == 5 || Otp == 7)
                sym = new OcadRectSymbol();
            else if (Otp == 6)
                sym = new OcadLineTextSymbol();
            else {
                Debug.Assert(false);
                return null;
            }

			sym.Size = Size;
			sym.Sym = Sym;
			sym.Otp = Otp;
			sym.SymTp = SymTp;
			sym.Flags = Flags;
            if (version <= 8)
			    sym.Extent = reader.ReadInt16();
			sym.Selected = (reader.ReadByte() != 0) ? true : false;
			sym.Status = reader.ReadByte();

            if (version <= 8) {
                sym.Tool = reader.ReadInt16();
                sym.FrWidth = reader.ReadInt16();
            }
            else {
                sym.Tool = reader.ReadByte();
                sym.CsMode = reader.ReadByte();
                sym.CsObjType = reader.ReadByte();
                sym.CsCdFlags = reader.ReadByte();
                sym.Extent = reader.ReadInt32();
            }

			sym.FilePos = reader.ReadInt32();

            if (version <= 8) {
                sym.ColorSet = Util.ReadByteArray(reader, 32);
            }
            else {
                sym.Group = reader.ReadInt16();
                sym.nColors = reader.ReadInt16();
                sym.ColorsUsed = new short[sym.nColors];
                for (int i = 0; i < 14; ++i) {
                    short colorId = reader.ReadInt16();
                    if (i < sym.nColors)
                        sym.ColorsUsed[i] = colorId;
                }
            }

			sym.Description = Util.ReadDelphiString(reader, 31);
			sym.IconBits = Util.ReadByteArray(reader, (version <= 8) ? 264 : 484);

			sym.ReadExtra(reader, version);

			return sym;
		}