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; }
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); }
AreaSymbol CreateAreaSymbol(OcadObject obj, AreaSymDef symdef) { if (symdef == null) throw new OcadFileFormatException("Object has unknown or inconsistent symbol type {0}", obj.Sym); SymPathWithHoles path = CreateAreaSymPath(obj.coords); return new AreaSymbol(symdef, path, AngleToDegrees(obj.Ang)); }
public AreaSymbol(AreaSymDef def, SymPathWithHoles path, float angle) { this.def = def; this.path = path; this.angle = angle; boundingBox = def.CalcBounds(path); }