Giter Club home page Giter Club logo

acadsvg's Introduction

ACad/SVG

ACad/SVG is a library to convert AutoCAD DWG documents to SVG. DWG documents are read with ACadSharp.

The converter supports many AutoCAD entities such as Arc, Circle, Dimensions, Ellipse, Hatch, Insert, Leader, Line, LwPolyline, MText, Multileader, Spline, TextEntity. The converter focuses on converting the block structure, especially dynamic blocks, rather than just converting a drawing.

SVG text is created using SvgElements.

Getting Started

Use the ACad SVG Studio to load and convert DWG documents and view the converted SVG.

Code Example

using ACadSvg;
using SvgElements;

//  Create conversion context assuming standard conversion options.
//  The conversion context also receives the conversion log.
//  See/use ACadSvgStudio to learn more about conversion options.
ConversionContext ctx = new ConversionContext();

string path = "sample.dwg";
DocumentSvg docSvg = ACadLoader.LoadDwg(path, ctx);

//  Get an object representing a SVG group containing the converted
//  entities that are not member of a BlockRecord.
SvgElementBase mainGroup = docSvg.MainGroupToSvgElement();

//  Get an object representing a SVG defs element containing the converted
//  BlockRecord objects found in DWG.
SvgElementBase defs = docSvg.DefsToSvgElement();

//  Create an empty SVG element
SvgElement svg = DocumentSvg.CreateSVG(ctx);

//  Convert the SVG objects to Text
string mainGroupSvg = mainGroup.ToString();
string defsSvg = defs.ToString();

Console.WriteLine(ctx.ConversionInfo.GetLog());
Console.WriteLine(ctx.ConversionInfo.GetOccurringEntitiesLog());

Dependencies

NOTE: Currently not all ACadSharp features required by ACadSvg are pushed to ACadSharp. Please use the "merged" branch from this repository.

WIP

The converter does not support all AutoCAD entities. Entitiy types that could not be converted, either because the conversion is not implemented in ACad/SVG or the DWG reader is not implemented in ACadSharp are listed in the conversion log.

Notice that this project is in an alpha version, not all the features are implemented and there can be bugs due to this.

Contributions

Please feel free to fork this repo and send a pull request if you want to contribute to this project.

acadsvg's People

Contributors

mme1950 avatar nka1994 avatar

Stargazers

 avatar  avatar  avatar  avatar Mike Smart avatar David avatar Manfredi avatar Timm avatar

Watchers

Timm avatar

acadsvg's Issues

Test Findings, Comments

  • Comments
  • Enhance Conversion options: Class attribute must receive layer and object type (important for test)
  • Viewbox, GlobalAttributes options
  • Bug: Ellipse evaluates Rx=0, Ry=0
  • #3
  • Decimal numbers in stroke dasharray must have dots as decimal separator.
  • #6
  • #4

LEADER: Arrowhead scaling

The LEADER entity has no properties that determine the type and size of the arrowhead. A boolean flag ArrowheadEnabled determines whether or not the arrowhead is visble.

Assumptions to be verified by DWG samples:

  • All properties of the arrowhead except a custom size factor must be read from the associated DIMSTYLE object.
  • The standard arrowhead is a filled triangle and must be created.
  • Other standard arrowheads or custom arrowheads are defined by the LeaderArrow property.
  • The arrowhead size is determined by the ArrowSize property.
  • The ScaleFactor property may have to be considered. ScaleFactor may be 0.

A explicitly set arrowhead size appears in the extended data ot the LEADER object.

Conversion option GroupFilterRegex, GroupFilterMode

Block/BlockRecord objects read from the AutoCAD-File are converted to SVG group elements. But not all groups are relevant.
Groups shall be be filtered by their names using a regular expression. The filter shall be applied as exclude or include filter.

Line Weight

Line weight is currently not handled.
In some cases hard coded stroke-width is set.

see

Tasks:

  • Implement Utils method:
  • Lineweight is represented as enum LineweightType:
    • Negative values represent ByBlock=-2, ByLayer=-1
    • Default=-3 maps to some global parameter? --> Investigate!
    • ByDips=-4 --> Invaestigate!
    • Positive Values immediate line-width values
  • Do we need a scale factor?
  • Does the effective line width on the drawing size?

Collateral

  • move protected ConversionContext _ctx to EntitySvg
    EntitySvg Constructor takes ctx, all entities call base(ctx).

Apply for:

  • Arc
  • Circle
  • DimensoinLinear
  • DimensionAngular3Pt
  • Ellipse
  • Leader
  • Line
  • LwPolyline
  • MultiLeader
  • Point
  • Polyline2D
  • Polyline3D
  • Spline

Collateral:

  • Solid (no outline fill using Entity.Color)

MTEXT line break

  • Text may contain line break (\n) instead of \P.
  • Attachment type, Alignment is not properly handled.
  • Wrapped text.

Display output in a browser

I am trying to use this project to translate an AutoCAD file into something a user can view in a browser. I have used the sample code here to generate the mainGroupSvg and defsSvg strings but I don't know how to use that for displaying in a browser.

I have also downloaded the project "ACadSvgStudio". It will run and open dwg files, but not display them in its browser window.

Can you give me a hint on how to do this?

Thanks!

Use MultiLeaderProperties class

A new class MuliLeaderProperties has been created with #58.
This class provides effective MultiLeader style properties from various sources, PropertyOverrideFlags control which data are to be used:

  • MultileaderStyle
  • Context
  • MultiLeader (explicit Properties, extended Data)

These data must be used in MultiLeaderSvg.

Multileader: Text and Text Frame

  • The position and the size text frame is not correct.
  • Text size seems to be wrong (sometimes).
  • Dogleg is always drawn, also if "no dogleg" is chosen in AutoCAD (where can we find this info in the data received from DWG)

LWPOLYLINE: Bulge --> AddArc

LWPOLYLINE vertices can have a bulge property.
bulge defines circular arc between the this vertex and the next vertex.

Dimension Class Hierarchy

The DimensionSvg class ist the the base class for all Dimension ... Svg classes. It shall provide access to the DimensionProperties object, store some values that are to be used by all types of dimension entities and provide some commonly used methods, e.g., to create dimension-line or extension-line SVG elements.

Dimension-text formatting: primary, alternate, tolerance

The measurement text can in AutoCAD be specified explicitly. In this case this text displayed as it is.

If no explicit text is specified the measurement text must be created using a set of properties defined by the DimensionStyle object associated with the Dimenison object. All properties can be overridden by Dimension object's ExtendedData.

The measurement text contains

  • a primary part, essentially containing the measurement,
  • optionally an alternate-unit part containing the measurement in a alternate scale or style,
  • both parts can be enriched with a tolerance in various style.

The primary part and alternate part respectively can be formatted in various styles, specified by the enums defiened in ACadSharp:

  • LinearUnitFormat for linear dimensions
  • AngularUnitFormat for angular dimensions

To create a measurement text based on the effective DimensionStyle properties both the parts of the measurement text and the style must be considered.

Linear Dimension Line: Full Implementation

Currently only linear dimension lines are converted correctly.

  • Dimension line with arbitrary angle
  • Extension line offset and extension
  • Arrow inside/arrow outside, arrowhead size
  • Arrow from Block, size, angle
  • Dimension Text with Leader

Lineweight scaling

Lineweight is specified by enum values ranging from 5 to 210 representing hundredths of millimeters defined in WCS.
To assign a reasonable stroke-witdth this value must be scaled.
We did not find a suitable setting in the document header.

The scale factor should depend on the model-space extent. This, however, is not good enaugh considereing the DWG samples we have.
Thus a scale factor specified in the conversion options is to be used.

Strategy:

  • The lineweight value in hundredth of millimeters is mustiplied with a scale factor.
  • The scale factor can be specified as conversion option.
  • If a scale factor o zero is specified, a scale factor is calculated from the model-space extent: max(x-width, y-width) / 2500

Unificataion/refactoring

  • ConversionContext.BlocksInDefs should be internal.
  • Initialize all members of the ConversionContext to enable easy creation of sample app.
  • ConversionInfo: New method to get OccurringEntities as multiline string.
  • GloabalAtttributeData constructor without parameters, all properties must be initialized to enable easy creation of sample app.

Point

In AutoCAD several shapes can be selected for a Point.
The point symbol and size can be read from the document header: PointDisplayMode=$PDSTYLE, PointDisplaySize=$PDSIZE.
PointDisplayStyle in the lower 3 bits contains an enum value representing the interiour: dot (0), empty (1), plus (2), x (3), line-up (4), and the flags circle (32) and square (64).

Color ...

  • Detect true colors in extended data
  • Refactor color ByBlock, ByLayer
  • As HTML color

Hatch patterns

  • The Concrete Pattern does not work.
  • Patterns must be created from the data received from AutoCAD.
  • Problem to be solved: Pattern is reusable, hatch defines the pattern color.

Retrieve Extended-Data properties, fallback to Dimension-Style properties.

Standard properties of a Dimension... entity are specified by the associated DimensionStyle object. The standard values may be overridden by the entity's extended data.

A mechanism to retrieve effective property values, i.e. values from the extended data, if specified, defaulting to the properties of the DimensionStyle, is to be implemented.

Entity's Extended Data Overriding DimensionStyle Properties

Extended data for an etitiy appear as ExtendedDataDictionary. Entries of type ExtendedData refer to an AppId"/>. An ExtendedData entry contains a list of ExtendedDataRecord records. An ExtendedDataRecord contains a Code and a Value. The Code specifies the the data type of the value. An ExtendedDataRecord does not contain any information about purpose of the value.

The ExtendedData may have different structures. ExtendedData of Dimension and Leader entities contain entries that are organized as follows:

  • The first record contains the name of DSTYLE indicating that the values of the ExtendedData provide property values to override values of the DimensionStyle object.
  • We found out that the preceding record contains a group code defining the meaning of the value of this record. The group code matches the group code of the property to be overridden.

Example:
When in AutoCAD for a LEADER a custom arrowsize is set, the value appears in an ExtendedData entry associated with the AppId key having the name ACAD. If an entry with the "type" record containing DSTYLE is found and a record with the group code 41 appears the following record contains the arrow-size value.

DocumentSvg refactoring

  • The static CreateSvg method should be moved to DocumentSvg
  • The conversion of BlockRecords should be called in the constructor.
  • Separate ToSvg methods shall be implemented:
    MainGroupToSvgElement
    DefsToSvgElement
    ToSvgElement

Spline: Implement "real" SVG spline

Currently Splines are approximated with a polygone.

The AutoCAD SPLINE entitiy uses two alternative concepts to define a arbitraty smoth curve see:

  • Control points (max 10) fo a Bezier/B-Spline curve,
  • Fit points to be interpolated by cubic splines.

Settings Rework

  • Conversion context constructor (to pass this conversion context to new BlockRecordsSvg.
  • New conversion option DefauldLineWeight
    AutoCAD stores the default line weight in the registry, not suitable for ACadSvg. A new field DefauldLineWeight is needed in the ConversionOptions class.
  • new global setting StrokeWidthEnabled.

LwPolylineSvg: Bulge for Closing Leg

A closed polyline that may have a bulge at the last vertex cannot be closed with a z-clause in the d-attribute of the SVG path element.
It must be must be closed with a leg to the first vertex with the bulge of the last vertex.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.