Package com.luciad.format.dwg
Class TLcdDWGModelDecoder
java.lang.Object
com.luciad.format.dwg.TLcdDWGModelDecoder
- All Implemented Interfaces:
ILcdDWGModelDecoder,ILcdInputStreamFactoryCapable,ILcdModelDecoder
@LcdService(service=ILcdModelDecoder.class,
priority=20000)
public class TLcdDWGModelDecoder
extends Object
implements ILcdDWGModelDecoder, ILcdInputStreamFactoryCapable
This model decoder decodes vector data in AutoCAD's drawing format.
The current implementation supports DWG/DXF versions up to R2018.
Input files
| File | Required | Entry point | Description |
|---|---|---|---|
| *.dwg/*.dxf | x | x | Drawing file containing vector data |
Supported file transfer protocols
- This model decoder supports all transfer protocols that are supported by
the
inputStreamFactoryof this decoder.
Model structure
- This model decoder creates a model per DWG file.
- All models returned by this model decoder implement
ILcd2DBoundsIndexedModel. - The models are expose any DWG extented entries through its data model. See further for more details.
Model descriptor
- All models returned by this model decoder have a
TLcdDWGModelDescriptor. Among other information, the descriptor contains the list of DWG layers and line styles. - The type name of the model descriptor is the display name of this decoder.
- The model descriptor returned by this model decoder is a
TLcdDataModelDescriptor. Its data model exposes the DWG extended entities in a uniform way.
Model reference
The model reference is obtained from anILcdModelReferenceDecoder. The default reference decoder set on this
model decoder is based on all model reference decoders annotated with the LcdService annotation, and can handle
- EPSG references (
<filename>.epsg): seeTLcdEPSGModelReferenceDecoderfor more info. - WKT references (
<filename>.prj): seeTLcdWKTModelReferenceDecoderfor more info. - Luciad encoded model references (
<filename>.ref): seeTLcdModelReferenceDecoderfor more info.
Model elements
- Decoded models contain elements that all implement
ILcdDWGShape. - All elements are
ILcdDataObjects. If the element has any extended data associated with it, the data object is an "ExtendedEntitiesList" that has a property "entities" that is the list of entries.
| DWG element type | DWG element name | Decoded object |
|---|---|---|
| 1 | TEXT | |
| 2 | ATTRIB | |
| 4 | BLOCK | |
| 5 | ENDBLK | |
| 6 | SEQEND | |
| 7 | INSERT | |
| 8 | MINSERT | |
| 10 | VERTEX_2D | |
| 11 | VERTEX_3D | |
| 15 | POLYLINE_2D | |
| 16 | POLYLINE_3D | |
| 17 | ARC | |
| 18 | CIRCLE | |
| 19 | LINE | |
| 27 | POINT | |
| 28 | FACE_3D | |
| 31 | SOLID | |
| 35 | ELLIPSE | |
| 36 | SPLINE | |
| 37 | REGION | |
| 44 | MTEXT | |
| 45 | LEADER | |
| 47 | MLINE | |
| 48 | BLOCK_CONTROL | |
| 49 | BLOCK_HEADER | |
| 50 | LAYER_CONTROL | |
| 51 | LAYER | |
| 57 | LTYPE | |
| 77/varies | LWPLINE | |
| 78/varies | HATCH | |
- Hatched objects are only outlined, not filled. If a HATCH object contains
a single closed path (polygon) the returned object will be a
TLcdDWGSolid. If it contains more paths, the decoder will return aTLcdDWGBlockcontaining oneTLcdDWGSolidfor each path. - In compatibility mode, the same types of objects are created as
in pre-10.1 versions and no additional extended entity data
are decoded. If backward compatibility mode is off (the default),
TLcdDWGCompositeRingandTLcdDWGCompositeCurveobjects are created for solids, polylines and hatches containing bulges. Also, the extended entity info item types are correctly filled in and layer reference and registered application name items are decoded. You can enable backwards compatibility mode using the system propertydwg.decoder.compatibility=true.
Useful settings
- By default, invisible objects and invisible or frozen layers are not decoded. You can modify this behavior using the following methods:
- By default, extended entity data are decoded. You can control the decoding of extended entity data based on the data types you are interested in, using the following methods: In addition, you can specify the extended entity strings you are interested in, as described in the following paragraph.
- By default, all extended entity strings are decoded. You can control the decoding of extended entity strings based on the string prefixes you are interested in, using the following methods:
- Starting with version 10.1 the decoding is delegated to the Open Design Alliance "Teigha"
native library. The old implementation is still available and can be activated using the
dwg.decoder.legacy=truesystem property, but it will not be able to decode Autocad 2018+ DWG data files.
Sample code
ILcdModelDecoder decoder =
new TLcdDWGModelDecoder(new TLcdEPSGModelReferenceDecoder(),
new TLcdGeodeticReference(new TLcdGeodeticDatum()));
ILcdModel model = decoder.decode("vectordata.dwg");
Performance tips
- Invisible or frozen objects or layers are not decoded by default, potentially saving some memory and some processing time.
Thread safety
- The decoding of models is not thread-safe.
- The decoded models are thread-safe for read access.
Supported versions and specifications
- DWG and DXF
- Up to 2018 (including R13C3, R14, R2000, R2004, R2007, R2010, R2013 and R2018)
Known limitations
- The current implementation does not support hatching.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTLcdDWGModelDecoder.TLcdDWGModelDecoder(ILcdModelReference aDefaultModelReference) Creates a newTLcdDWGModelDecoder.TLcdDWGModelDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder) Creates a newTLcdDWGModelDecoder.TLcdDWGModelDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder, ILcdModelReference aDefaultModelReference) Creates a newTLcdDWGModelDecoder. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExtendedEntityString(String aStringPrefix) Adds a string prefix to the set of prefixes that determine which extended entity strings are decoded.voidaddExtendedEntityType(int aType) Adds a DWG extended entity type to the set of types that is decoded.booleanChecks whether this model decoder can decode the specified data source.voidClears the set of DWG extended entity strings that is decoded.voidClears the set of DWG extended entity types that is decoded.Creates a new model from the given data source.Returns the default model reference for decoded models.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder.Returns the input stream factory that is used.Returns the model reference decoder that is for creating model references for decoded models.booleanReturns whether DWG layers that are marked as frozen are decoded.booleanReturns whether DWG layers that are marked as invisible are decoded.booleanReturns whether DWG objects that are marked as invisible are decoded.voidResets the set of DWG extended entity strings that is decoded.voidResets the set of DWG extended entity types that is decoded.voidsetDecodeFrozenLayers(boolean aDecodeFrozenLayers) Specifies whether DWG layers that are marked as frozen should be decoded.voidsetDecodeInvisibleLayers(boolean aDecodeInvisibleLayers) Specifies whether DWG layers that are marked as invisible should be decoded.voidsetDecodeInvisibleObjects(boolean aDecodeInvisibleObjects) Specifies whether DWG objects that are marked as invisible should be decoded.voidsetDefaultModelReference(ILcdModelReference aDefaultModelReference) Sets the default model reference for decoded models, in case the model reference decoder doesn't provide one.voidsetExtendedEntityStringSelection(String[] aStringPrefixes) Sets the set of DWG extended entity strings that is decoded.voidsetExtendedEntityTypeSelection(int[] aTypes) Sets the set of DWG extended entity types that is decoded.voidsetInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory) Sets the input stream factory to be used.voidsetModelReferenceDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder) Sets the model reference decoder that will be used for creating model references for decoded models.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Constructor Details
-
TLcdDWGModelDecoder
public TLcdDWGModelDecoder()Creates a newTLcdDWGModelDecoder. -
TLcdDWGModelDecoder
Creates a newTLcdDWGModelDecoder.- Parameters:
aModelReferenceDecoder- the model reference decoder that can assign references to decoded models.
-
TLcdDWGModelDecoder
Creates a newTLcdDWGModelDecoder.- Parameters:
aDefaultModelReference- the model reference that decoded models will get if the model reference decoder can't decode one.
-
TLcdDWGModelDecoder
public TLcdDWGModelDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder, ILcdModelReference aDefaultModelReference) Creates a newTLcdDWGModelDecoder.- Parameters:
aModelReferenceDecoder- the model reference decoder that can assign references to decoded models.aDefaultModelReference- the model reference that decoded models will get if the model reference decoder can't decode one.
-
-
Method Details
-
setInputStreamFactory
Description copied from interface:ILcdInputStreamFactoryCapableSets the input stream factory to be used.- Specified by:
setInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Parameters:
aInputStreamFactory- the input stream factory to be used.
-
getInputStreamFactory
Description copied from interface:ILcdInputStreamFactoryCapableReturns the input stream factory that is used.- Specified by:
getInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Returns:
- the input stream factory that is used.
-
getDefaultExtension
- Returns:
- "dwg".
-
setModelReferenceDecoder
Description copied from interface:ILcdDWGModelDecoderSets the model reference decoder that will be used for creating model references for decoded models. The default isnull.- Specified by:
setModelReferenceDecoderin interfaceILcdDWGModelDecoder
-
getModelReferenceDecoder
Description copied from interface:ILcdDWGModelDecoderReturns the model reference decoder that is for creating model references for decoded models.- Specified by:
getModelReferenceDecoderin interfaceILcdDWGModelDecoder
-
setDefaultModelReference
Description copied from interface:ILcdDWGModelDecoderSets the default model reference for decoded models, in case the model reference decoder doesn't provide one. The default isnull.- Specified by:
setDefaultModelReferencein interfaceILcdDWGModelDecoder
-
getDefaultModelReference
Description copied from interface:ILcdDWGModelDecoderReturns the default model reference for decoded models.- Specified by:
getDefaultModelReferencein interfaceILcdDWGModelDecoder
-
setDecodeInvisibleObjects
public void setDecodeInvisibleObjects(boolean aDecodeInvisibleObjects) Description copied from interface:ILcdDWGModelDecoderSpecifies whether DWG objects that are marked as invisible should be decoded. The default isfalse.- Specified by:
setDecodeInvisibleObjectsin interfaceILcdDWGModelDecoder
-
isDecodeInvisibleObjects
public boolean isDecodeInvisibleObjects()Description copied from interface:ILcdDWGModelDecoderReturns whether DWG objects that are marked as invisible are decoded.- Specified by:
isDecodeInvisibleObjectsin interfaceILcdDWGModelDecoder
-
setDecodeInvisibleLayers
public void setDecodeInvisibleLayers(boolean aDecodeInvisibleLayers) Description copied from interface:ILcdDWGModelDecoderSpecifies whether DWG layers that are marked as invisible should be decoded. The default isfalse.- Specified by:
setDecodeInvisibleLayersin interfaceILcdDWGModelDecoder
-
isDecodeInvisibleLayers
public boolean isDecodeInvisibleLayers()Description copied from interface:ILcdDWGModelDecoderReturns whether DWG layers that are marked as invisible are decoded.- Specified by:
isDecodeInvisibleLayersin interfaceILcdDWGModelDecoder
-
setDecodeFrozenLayers
public void setDecodeFrozenLayers(boolean aDecodeFrozenLayers) Description copied from interface:ILcdDWGModelDecoderSpecifies whether DWG layers that are marked as frozen should be decoded. The default isfalse.- Specified by:
setDecodeFrozenLayersin interfaceILcdDWGModelDecoder
-
isDecodeFrozenLayers
public boolean isDecodeFrozenLayers()Description copied from interface:ILcdDWGModelDecoderReturns whether DWG layers that are marked as frozen are decoded.- Specified by:
isDecodeFrozenLayersin interfaceILcdDWGModelDecoder
-
resetExtendedEntityTypeSelection
public void resetExtendedEntityTypeSelection()Description copied from interface:ILcdDWGModelDecoderResets the set of DWG extended entity types that is decoded. All extended entity data types will now be included in the models when decoding DWG files.- Specified by:
resetExtendedEntityTypeSelectionin interfaceILcdDWGModelDecoder- See Also:
-
clearExtendedEntityTypeSelection
public void clearExtendedEntityTypeSelection()Description copied from interface:ILcdDWGModelDecoderClears the set of DWG extended entity types that is decoded. None of the extended entity data types will now be included in the models when decoding DWG files.- Specified by:
clearExtendedEntityTypeSelectionin interfaceILcdDWGModelDecoder- See Also:
-
setExtendedEntityTypeSelection
public void setExtendedEntityTypeSelection(int[] aTypes) Description copied from interface:ILcdDWGModelDecoderSets the set of DWG extended entity types that is decoded. Only extended entity data with the specified types will now be included in the models when decoding DWG files.- Specified by:
setExtendedEntityTypeSelectionin interfaceILcdDWGModelDecoder- Parameters:
aTypes- a list of extended entity types.- See Also:
-
addExtendedEntityType
public void addExtendedEntityType(int aType) Description copied from interface:ILcdDWGModelDecoderAdds a DWG extended entity type to the set of types that is decoded.- Specified by:
addExtendedEntityTypein interfaceILcdDWGModelDecoder- Parameters:
aType- an extended entity type.- See Also:
-
resetExtendedEntityStringSelection
public void resetExtendedEntityStringSelection()Description copied from interface:ILcdDWGModelDecoderResets the set of DWG extended entity strings that is decoded. All DWG extended entity strings will now be included in the models when decoding DWG files.- Specified by:
resetExtendedEntityStringSelectionin interfaceILcdDWGModelDecoder- See Also:
-
clearExtendedEntityStringSelection
public void clearExtendedEntityStringSelection()Description copied from interface:ILcdDWGModelDecoderClears the set of DWG extended entity strings that is decoded. None of the DWG extended entity strings will now be included in the models when decoding DWG files.- Specified by:
clearExtendedEntityStringSelectionin interfaceILcdDWGModelDecoder- See Also:
-
setExtendedEntityStringSelection
Description copied from interface:ILcdDWGModelDecoderSets the set of DWG extended entity strings that is decoded. Only DWG extended entity strings with the specified prefixes will now be included in the models when decoding DWG files.- Specified by:
setExtendedEntityStringSelectionin interfaceILcdDWGModelDecoder- Parameters:
aStringPrefixes- a list of string prefixes.
-
addExtendedEntityString
Description copied from interface:ILcdDWGModelDecoderAdds a string prefix to the set of prefixes that determine which extended entity strings are decoded.- Specified by:
addExtendedEntityStringin interfaceILcdDWGModelDecoder- Parameters:
aStringPrefix- a list of string prefixes.
-
getDisplayName
Description copied from interface:ILcdModelDecoderReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder.- Specified by:
getDisplayNamein interfaceILcdModelDecoder- Returns:
- the displayable name of this
ILcdModelDecoder.
-
canDecodeSource
Description copied from interface:ILcdModelDecoderChecks whether this model decoder can decode the specified data source. It is acceptable for this method to returntruefor a source name whiledecodethrows an exception for that same source name.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
s- the data source to be verified; typically a file name or a URL.- Returns:
trueif this decoder can likely decode the data specified by the source name,falseotherwise.- See Also:
-
decode
Description copied from interface:ILcdModelDecoderCreates a new model from the given data source.- Specified by:
decodein interfaceILcdModelDecoder- Parameters:
s- the data source to be decoded; typically a file name or a URL.- Returns:
- A model containing the decoded data. While
nullis allowed, implementors are advised to throw an error instead. - Throws:
IOException- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decode( String aSourceName ) throws IOException { try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }- See Also:
-