OpenCascade’s XDE for DXF drawing generator

Preface

Data loaded into an XDE document.

Setting up an XDE document

Handle(Doc) doc = new Doc;
int NewDoc(const Handle(asiTcl_Interp)& interp,
int argc,
const char** argv)
{
Handle(Doc) doc = new Doc;
interp->SetVar( "M", new cmdAsm_XdeModel(doc) );
}
OCAF browser.
User-friendly contents view of an XDE document.

XDE sections

Extension points

Contents of a “Layer” in an XDE document.

Case study: XDE for drawings

Adding an attribute

DASHED
70
0
3
Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _
72
65
73
2
40
19.05
49
12.7
74
0
49
-6.35
74
0
Custom linetype attribute in a layer.
Handle(XCAFDoc_LayerTool)
layerTool = XCAFDoc_DocumentTool::LayerTool( doc->Main() );

TDF_Label bendsLayerLab = layerTool->FindLayer("FOLD_LINES");
Handle(DxfLinetypeAttr) linetypeAttr;

// Set linetype attribute to the corresponding layer.
if ( !bendsLayerLab.IsNull() )
{
linetypeAttr = DxfLinetypeAttr::Set(bendsLayerLab);
linetypeAttr->SetLinetype(ltype);
}

Enhancing the translator

Customized data translation workflow.
bool WriteLinetypes(const Handle(TDocStd_Document)& doc)
{
Handle(DxfSection_Model)
dxfModel = Handle(DxfSection_Model)::DownCast( WS()->Model() );

// Find the DXF layer entity to fill with the data from OCAF.
Handle(DxfSection_Layer)
layer = dxfModel->FindLayer("FOLD_LINES");

Handle(XCAFDoc_LayerTool)
layerTool = XCAFDoc_DocumentTool::LayerTool( doc->Main() );

// Find the linetype attribute.
TDF_Label bendsLayerLab = layerTool->FindLayer("FOLD_LINES");
Handle(fraAlgo_DxfLinetypeAttr) linetypeAttr;

if ( !bendsLayerLab.FindAttribute(DxfLinetypeAttr::GUID(),
linetypeAttr) )
return false;

// Get linetype entity.
const Handle(DxfSection_LType)&
ltype = linetypeAttr->GetLinetype();

// Pass linetype to the layer.
layer->SetLineType( ltype->GetName() );

// Find a table with linetypes.
Handle(DxfSection_Table)
ltypesTbl = dxfModel->FindTable("LTYPE", false);

// Add linetype to the LTYPE table.
Handle(DxfSection_HSequenceOfObject)
objects = ltypesTbl->GetObjects();
//
objects->Append(ltype);
ltypesTbl->SetObjects(objects);

// Add entity, so that AssignHandles() can iterate the model
// to put unique identifiers (handles) for each entity, including
// the newly constructed linetype.
dxfModel->AddEntity(ltype);

return true;
}
A drawing with custom linetypes on a separate layer.

Wrapping up

Another drawing with custom linetypes on a separate layer.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store