Пример #1
0
        void WriteAreaSymDef(AreaSymDef symdef)
        {
            OcadAreaSymbol symbol = new OcadAreaSymbol();
            FillInCommonSymdef(symbol, symdef);

            symbol.Otp = 3;
            symbol.SymTp = 0;
            symbol.Extent = 0;
            symbol.FillOn = symdef.FillColor != null;
            if (symdef.FillColor != null)
                symbol.FillColor = NumberOfColor(symdef.FillColor);

            if (symdef.BorderSymdef != null) {
                // A border symbol. Supported directly in OCAD 9. Must be emulated by writing additional objects in 6-8,
                // which is handled elsewhere.
                if (version >= 9) {
                    symbol.BorderOn = true;
                    symbol.BorderSym = ConvertSymdefId(symdef.BorderSymdef.OcadID);
                }
            }

            int hatchMode;
            SymColor hatchColor;
            float hatchWidth, hatchSpacing, angle1, angle2;

            symdef.GetHatching(out hatchMode, out hatchColor, out hatchWidth, out hatchSpacing, out angle1, out angle2);
            symbol.HatchMode = (short) hatchMode;
            if (hatchMode > 0) {
                symbol.HatchColor = NumberOfColor(hatchColor);
                symbol.HatchLineWidth = (short) ToOcadDimensions(hatchWidth);
                if (version >= 9)
                    symbol.HatchDist = (short) ToOcadDimensions(hatchSpacing);
                else
                    symbol.HatchDist = (short) ToOcadDimensions(hatchSpacing - hatchWidth);
                symbol.HatchAngle1 = AngleToOcad(angle1);
                symbol.HatchAngle2 = AngleToOcad(angle2);
            }

            bool drawPattern, offsetRows;
            float width, height, angle;
            Glyph glyph;
            symdef.GetPattern(out drawPattern, out offsetRows, out width, out height, out angle, out glyph);

            if (drawPattern) {
                symbol.StructMode = (short) (offsetRows ? 2 : 1);
                symbol.StructWidth = (short) ToOcadDimensions(width);
                symbol.StructHeight = (short) ToOcadDimensions(height);
                symbol.StructAngle = AngleToOcad(angle);
                symbol.StructElts = SymbolEltsFromGlyph(glyph, out symbol.DataSize);
            }

            symbol.Write(writer, version);
        }
Пример #2
0
        SymDef CreateAreaSymdef(string name, int ocadID, OcadAreaSymbol ocadSym)
        {
            SymColor color;
            AreaSymDef symdef;
            LineSymDef borderSymdef = null;

            if (ocadSym.FillOn) {
                color = GetColor(ocadSym.FillColor);
            }
            else {
                color = null;
            }

            if (ocadSym.BorderOn) {
                if (!symdefids.ContainsKey(ocadSym.BorderSym))
                    throw new OcadFileFormatException("Invalid border sym {0} in symbol {1}", ocadSym.BorderSym, ocadSym.Sym);
                borderSymdef = (LineSymDef) symdefids[ocadSym.BorderSym];
            }

            symdef = new AreaSymDef(name, ocadID, color, borderSymdef);

            if (ocadSym.HatchMode > 0) {
                SymColor hatchColor = GetColor(ocadSym.HatchColor);
                symdef.SetHatching(ocadSym.HatchMode, hatchColor,
                    ToWorldDimensions(ocadSym.HatchLineWidth),
                    ToWorldDimensions((version <= 8) ? (ocadSym.HatchLineWidth + ocadSym.HatchDist) : ocadSym.HatchDist),
                    AngleToDegrees(ocadSym.HatchAngle1),
                    AngleToDegrees(ocadSym.HatchAngle2));
            }

            if (ocadSym.StructMode > 0) {
                symdef.SetPattern(true, (ocadSym.StructMode == 2),
                    ToWorldDimensions(ocadSym.StructWidth),
                    ToWorldDimensions(ocadSym.StructHeight),
                    AngleToDegrees(ocadSym.StructAngle),
                    CreateGlyph(ocadSym.StructElts));
            }

            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;
		}