In this example, a filter is created for importing components from a .cxf (Component Interchange Format) file. A library is created in the current job with the imported components. The library is opened in panel 1 from which you can select and place the component in the drawing.

Example

  Copy codeCopy code
<<filedescription>>
In this example, a filter is created for importing components 
from a .CXF (Component Interchange Format) file. 
A library is created in the current job with the imported components. 
The library is opened in panel 1 from which you can select and place the component in the drawing.
<<filedescription>>

function OnMenu()
{
  DlxApp.GetMenu(DlxApp.MENU_DWG).AddCommand("Import component from a CXF file...", 10, "Import a component from a file in .CXF format.\nImport Component");
  DlxApp.GetMenu(DlxApp.MENU_SCH).AddCommand("Import component from a CXF file...", 10, "Import a component from a file in .CXF format.\nImport Component");
  DlxApp.GetMenu(DlxApp.MENU_PCB).AddCommand("Import component from a CXF file...", 10, "Import a component from a file in .CXF format.\nImport Component");
}

function OnMenuUpdateCommand(cmd)
{
  switch (cmd.GetCommandId())
  {
  case 10:
    cmd.Enable(true);
    break;
  }
}

function OnMenuCommand(cmdId)
{
  switch (cmdId)
  {
  case 10:
    ImportComponent();
    break;
  }
}

///////////////////////////////////////////////////////////////////////////////

var libraryDoc = null;
var symbolsDoc = null;
var footprintsDoc = null;
var hotspotPoint = null;
var deviceFolder = null;
var currentComponent = null;
var importedComponents = 0;

function ImportComponent()
{
  // Remember the active document
  var activeDocument = DlxApp.GetActiveDocument();

  // Acquire the file to import
  var cxfFile = new DlxFile("", DlxApp.FILEOPEN_OPENDIALOG|DlxApp.FILEOPEN_ALLFILES, -1, "Component Interchange Format|*.cxf|Compressed archive|*.zip");
  if (!cxfFile.IsValid())
    return;

  // If it is a compressed archive, look for the .cxf file
  if (cxfFile.GetFileExt() == ".zip")
  {
    if (!cxfFile.Open(DlxApp.FILEOPEN_UNZIP))
    {
      throw new Error("File error.");
    }
    // Get 3D model
    for (var i = 0; i < cxfFile.GetItemsCount(); i++)
    {
      if (cxfFile.GetItemExt(i) == ".step")
        cxfFile.UnzipFile(i, DlxApp.GetFolder(DlxApp.FOLDERID_USER3DMODELS)+cxfFile.GetItemName(i));
    }
    // Open .cxf file
    cxfFile.Open(DlxApp.FILEOPEN_UNZIPTEXT, cxfFile.FindItemByExt(".cxf")); 
  }
  else
  {
    // If it is a .cxf file simply open it
    cxfFile.Open(DlxApp.FILEOPEN_READTEXT);
  }

  // Create library project
  var libraryProject = DlxApp.GetJob().GetProject("Library", true);
  if (!libraryProject.IsValid())
  {
    throw new Error("Error creating library project");
  }

  // Create symbols document
  symbolsDoc = libraryProject.GetDocument("Symbols", DlxApp.DOCTYPE_SCHEMATIC);
  if (!symbolsDoc.IsValid())
    symbolsDoc = libraryProject.NewDocument("Symbols", DlxApp.DOCTYPE_SCHEMATIC);
  if (!symbolsDoc.IsValid() || !symbolsDoc.Activate())
  {
    throw new Error("Error creating symbols document");
  }
  symbolsDoc.SetPageFormat("A4", true);
  // Set pen style to Symbol Body Outline
  symbolsDoc.SetStyle(new DlxPenStyle("#0000000000000000812FZZZZZZ"));
  // Set brush style to Symbol Body
  symbolsDoc.SetStyle(new DlxBrushStyle("#0000000000000000G10ZZZZZZZ"));
  // Set text style to Attribute Text
  symbolsDoc.SetStyle(new DlxTextStyle("#0000000000000001810KZZZZZZ"));
  // Set ref and value style to Attribute Text
  symbolsDoc.SetValueStyle(new DlxTextStyle("#0000000000000001810KZZZZZZ"));
  symbolsDoc.SetReferenceStyle(new DlxTextStyle("#0000000000000001810KZZZZZZ"));

  // Create footprints document
  footprintsDoc = libraryProject.GetDocument("Footprints", DlxApp.DOCTYPE_PCB);
  if (!footprintsDoc.IsValid())
    footprintsDoc = libraryProject.NewDocument("Footprints", DlxApp.DOCTYPE_PCB);
  if (!footprintsDoc.IsValid() || !footprintsDoc.Activate())
  {
    throw new Error("Error creating footprints document");
  }
  footprintsDoc.SetPageFormat("A4", true);
  hotspotPoint = new DlxPoint(footprintsDoc.GetPageWidth() / 2, footprintsDoc.GetPageHeight() / 2);
  // Set pen style by layer
  footprintsDoc.SetStyle(new DlxPenStyle(DlxApp.STYLE_BYLAYER));
  // Set brush style to Null
  footprintsDoc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_NULL));
  // Set attribute, ref and value style to BYLAYER
  footprintsDoc.SetValueStyle(new DlxTextStyle(DlxApp.STYLE_BYLAYER));
  footprintsDoc.SetReferenceStyle(new DlxTextStyle(DlxApp.STYLE_BYLAYER));
  footprintsDoc.SetAttributeStyle(new DlxTextStyle(DlxApp.STYLE_BYLAYER));

  // Create library document
  libraryDoc = libraryProject.GetDocument("Devices", DlxApp.DOCTYPE_LIBRARY);
  if (!libraryDoc.IsValid())
    libraryDoc = libraryProject.NewDocument("Devices", DlxApp.DOCTYPE_LIBRARY)
  if (!libraryDoc.IsValid() || !libraryDoc.Activate())
  {
    throw new Error("Error creating library document");
  }

  importedComponents = 0;
  currentComponent = new item_Component();
  deviceFolder = libraryDoc.GetFolder();

  // Reading .CXF file
  while (!cxfFile.IsEOF())
  {
    var fields = cxfFile.ReadLine().split("\t");
    switch (fields[0])
    {
    case "COMPONENT":
      BuildComponent();
      Read_Component(cxfFile, fields);
      break;
    case "PACKAGE":
      Read_Package(cxfFile, fields); 
      break;
    case "SYMBOL":
      Read_Symbol(cxfFile, fields);
      break;
    case "PAD":
      Read_Item(cxfFile, fields, new item_Pad(), Fill_Pad);
      break;
    case "PIN":
      Read_Item(cxfFile, fields, new item_Pin(), Fill_Pin);
      break;
    case "LINE":
      Read_Item(cxfFile, fields, new item_Line(), Fill_Line);
      break;
    case "TRIANGLE":
      Read_Item(cxfFile, fields, new item_Triangle(), Fill_Triangle);
      break;
    case "RECTANGLE":
      Read_Item(cxfFile, fields, new item_Rectangle(), Fill_Rectangle);
      break;
    case "POLYGON":
      Read_Item(cxfFile, fields, new item_Polygon(), Fill_Polygon);
      break;
    case "ARC":
      Read_Item(cxfFile, fields, new item_Arc(), Fill_Arc);
      break;
    case "DISK":
      Read_Item(cxfFile, fields, new item_Disk(), Fill_Disk);
      break;
    case "SPLINE":
      Read_Item(cxfFile, fields, new item_Spline(), Fill_Spline);
      break;
    case "TEXT":
      Read_Text(cxfFile, fields);
      break;
    }
  }
  BuildComponent();

  // Reactivate the working document
  activeDocument.Activate();

  // Finally, open the library in panel 1 and highlight the component
  if (importedComponents > 0)
  {
    DlxApp.GetJob().Save(); 
    DlxApp.OpenLibrary(DlxApp.GetJob().GetFileName());
    if (importedComponents == 1)
      DlxApp.GetLibraryPanel().Find(currentComponent.NAME);
  }
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function AdjustLength(value)
{
  value = parseFloat(value)/1000000;
  if (!currentComponent.readingSymbol)
    return value;
  // if symbol, snap to 2.5mm grid
  return value / 2.54 * 2.5;
}

function AdjustCoordX(value)
{
  return AdjustLength(value) + hotspotPoint.x;
}

function AdjustCoordY(value)
{
  return AdjustLength(value) + hotspotPoint.y;
}

function AdjustPinFunction(value)
{
  switch (value)
  {
  case 0 : return DlxApp.PINTYPE_UNDEFINED;
  case 1 : return DlxApp.PINTYPE_INPUT;
  case 2 : return DlxApp.PINTYPE_OUTPUT;
  case 3 : return DlxApp.PINTYPE_BIDIRECTIONAL;
  case 4 : return DlxApp.PINTYPE_OPENCOLLECTOR;
  case 5 : return DlxApp.PINTYPE_POWER;
  case 6 : return DlxApp.PINTYPE_PASSIVE;
  case 7 : return DlxApp.PINTYPE_THREESTATE;
  case 8 : return DlxApp.PINTYPE_POWEROUTPUT;
  case 9 : return DlxApp.PINTYPE_UNDEFINED;
  }
  return DlxApp.PINTYPE_UNDEFINED;
}

function AdjustLineDashed(value)
{
  switch (value)
  {
  case 0 : return "SOLID";
  case 1 : return "DOT";
  case 2 : return "DASHED";
  case 3 : return "DASHDOT";
  case 4 : return "DIVIDE";
  }
  return "SOLID";
}

function Context_AdjustLayer(layer)
{
  if (!this.bIsPackage)
    return this.layerSymbols;
  switch (layer)
  {
  case 2: // Copper top
    return this.layerTOPCOPPER;
  case 3: // Position print bottom
    return this.layerBOTSILK;
  case 4: // Position print top
    return this.layerTOPSILK;
  case 8: // Area bottom
    return this.layerBOTCOURTYARD;
  case 9: // Area inside
  case 10: // Area top
    return this.layerTOPCOURTYARD;
  case 11: // Solder mask bottom
    return this.layerBOTRESISTMASK;
  case 12: // Solder mask top
    return this.layerTOPRESISTMASK;
  case 14: // Solder paste bottom
    return this.layerBOTPASTEMASK;
  case 15: // Solder Paste top
    return this.layerTOPPASTEMASK;
  case 16: // Gold bottom
    return this.layerBOTGOLDMASK;
  case 17: // Gold top
    return this.layerTOPGOLDMASK;
  case 18: // Glue bottom
    return this.layerBOTGLUE;
  case 19: // Glue top
    return this.layerTOPGLUE;
  case 20: // Dimensioning
    return this.layerLIBRARYFRAMES;
  case 21: // PCB outline
  case 22: // Milling
    return this.layerTOPMECHANICAL;
  case 26: // Route prohibition (Copper bottom)
  case 27: // Route prohibition (Copper top)
  case 28: // Route prohibition (Copper inside)
  case 29: // Blind via prohibition top
  case 30: // Blind via prohibition bottom
  case 31: // Buried via prohibition
    return this.layerKEEPOUT;
  case 32: // Component names top
  case 33: // Component values top
    return this.layerTOPSILK;
  case 34: // Component names bottom
  case 35: // Component values bottom
    return this.layerBOTSILK;
  }
  return null;
}

function Context_SetPenStyle(layer, penstyle)
{
  if (layer.GetType() == DlxApp.LAYERTYPE_TOPCOURTYARD)
    this.doc.SetStyle(new DlxPenStyle(DlxApp.STYLE_BYLAYER)); // Set pen style to Courtyard objects
  else this.doc.SetStyle(penstyle);
}

function Context() {
  this.doc = null;
  this.page = null;
  this.device = null;
  this.bIsPackage = false;
  this.layerSymbols = null;
  this.layerLIBRARYFRAMES = null;
  this.layerTOPCOPPER = null;
  this.layerTOPRESISTMASK = null;
  this.layerBOTRESISTMASK = null;
  this.layerTOPPASTEMASK = null;
  this.layerBOTPASTEMASK = null;
  this.layerTOPGLUE = null;
  this.layerBOTGLUE = null;
  this.layerTOPSILK = null;
  this.layerBOTSILK = null;
  this.layerTOPCOURTYARD = null;
  this.layerBOTCOURTYARD = null;
  this.layerTOPINFO = null;
  this.layerTOPGOLDMASK = null; 
  this.layerBOTGOLDMASK = null;
  this.layerKEEPOUT = null;
  this.layerTOPMECHANICAL = null;
  this.layerTOPASSEMBLY = null;
  this.AdjustLayer = Context_AdjustLayer;
  this.SetPenStyle = Context_SetPenStyle;
};

function item_Component() {
  this.NAME = "";
  this.VALUE = "";
  this.PREFIX = "";
  this.SYMBOLS = 0;
  this.PACKAGE = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.symbolsList = [];
  this.package = new item_Package();
  this.currentItem = null;
  this.readingSymbol = true;
};

function item_Package() {
  this.NAME = "";
  this.X1 = 0;
  this.Y1 = 0;
  this.LAYER = 4;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.primitives = [];
};

function item_Symbol() {
  this.X1 = 0;
  this.Y1 = 0;
  this.LAYER = 101;
  this.SUFFIX = "";
  this.NUMBER = 1;
  this.ELEMENTS = 12;
  this.INSERT = true;
  this.SWAP = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.primitives = [];
};

function item_Pad() {
  this.XM = 0;
  this.YM = 0;
  this.WIDTH = 0;
  this.HEIGHT = 0;
  this.LAYER = 0;
  this.PINNUMBER = 0;
  this.FORM = 3;
  this.ROUNDED = 0;
  this.ROTATION = 0;
  this.DRILL = 0;
  this.LONG = 0;
  this.PADNAME = "";
  this.STOP = 0;
  this.PASTE = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Pad;
};

function item_Pin() {
  this.X1 = 0;
  this.Y1 = 0;
  this.PINNUMBER = 1;
  this.PINNAME = "";
  this.PINNAME = true;
  this.PINHIDE = false;
  this.LENGTH = 0;
  this.WIDTH = 0;
  this.LAYER = 1;
  this.PADNAME = "";
  this.ROTATION = 0;
  this.FUNCTION = AdjustPinFunction(6);
  this.SWAP = 0;
  this.INV = false;
  this.CLOCK = false;
  this.SHOWNUMBER = true;
  this.REF = false;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Pin;
};

function item_Line() {
  this.X1 = 0;
  this.Y1 = 0;
  this.X2 = 0;
  this.Y2 = 0;
  this.WIDTH = 0;
  this.LAYER = 4;
  this.DASHED = AdjustLineDashed(0);
  this.ROUNDED = true;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Line;
};

function item_Text() {
  this.CONTENT = "";
  this.X1 = 0;
  this.Y1 = 0;
  this.WIDTH = 0;
  this.HEIGHT = 0;
  this.LAYER = 4;
  this.WEIGHT = 10;
  this.ITALIC = false;
  this.RIGHT = false;
  this.FUNCTION = 1;
  this.HIDE = false;
  this.ROTATION = 0;
  this.DYN = true;
  this.MIRR = false;
  this.FONT = "arial";
  this.GERMAN = "";
  this.ENGLISH = "";
  this.FRENCH = "";
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Text;
};

function item_Triangle() {
  this.X1 = 0;
  this.Y1 = 0;
  this.X2 = 0;
  this.Y2 = 0;
  this.X3 = 0;
  this.Y3 = 0;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Triangle;
};

function item_Rectangle() {
  this.X1 = 0;
  this.Y1 = 0;
  this.WIDTH = 0;
  this.HEIGHT = 0;
  this.ROTATION = 0;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Rectangle;
};

function item_Polygon() {
  this.NODES = 0;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.pointsList = [];
  this.propertiesList = [];
  this.Build = BuildItem_Polygon;
};

function item_Arc() {
  this.XM = 0;
  this.YM = 0;
  this.X1 = 0;
  this.Y1 = 0;
  this.X2 = 0;
  this.Y2 = 0;
  this.RADIUS = 0;
  this.WIDTH = 0;
  this.START = 0;
  this.END = 0;
  this.DASHED = AdjustLineDashed(0);
  this.ROUNDED = true;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Arc;
};

function item_Disk() {
  this.XM = 0;
  this.YM = 0;
  this.RADIUS = 0;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Disk;
};

function item_Spline() {
  this.X1 = 0;
  this.Y1 = 0;
  this.X2 = 0;
  this.Y2 = 0;
  this.XA = 0;
  this.YA = 0;
  this.WIDTH = 0;
  this.LAYER = 0;
  this.PROPERTIES = 0;
  this.propertiesList = [];
  this.Build = BuildItem_Spline;
};

function Fill_Component(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "NAME":
      this.NAME = data[1];
      break;
    case "VALUE":
      this.VALUE = data[1];
      break;
    case "PREFIX":
      this.PREFIX = data[1];
      break;
    case "SYMBOLS":
      this.SYMBOLS = parseInt(data[1]);
      break;
    case "PACKAGE":
      this.PACKAGE = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Package(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "NAME":
      this.NAME = data[1];
      break;
    case "X1":
      this.X1 = parseInt(data[1]);
      break;
    case "Y1":
      this.Y1 = parseInt(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Symbol(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "SUFFIX":
      this.SUFFIX = data[1];
      break;
    case "NUMBER":
      this.NUMBER = parseInt(data[1]);
      break;
    case "ELEMENTS":
      this.ELEMENTS = parseInt(data[1]);
      break;
    case "INSERT":
      this.INSERT = (data[1] == "YES");
      break;
    case "SWAP":
      this.SWAP = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
     break;
    }
  }
}

function Fill_Pad(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "XM":
      this.XM = AdjustCoordX(data[1]);
      break;
    case "YM":
      this.YM = AdjustCoordY(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "HEIGHT":
      this.HEIGHT = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PINNUMBER":
      this.PINNUMBER = parseInt(data[1]);
      break;
    case "FORM":
      this.FORM = parseInt(data[1]);
      break;
    case "ROUNDED":
      this.ROUNDED = parseInt(data[1]);
      break;
    case "ROTATION":
      this.ROTATION = parseFloat(data[1]);
      break;
    case "DRILL":
      this.DRILL = AdjustLength(data[1]);
      break;
    case "LONG":
      this.LONG = AdjustLength(data[1]);
      break;
    case "PADNAME":
      this.PADNAME = data[1];
      break;
    case "STOP":
      this.STOP = parseInt(data[1]);
      break;
    case "PASTE":
      this.PASTE = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Pin(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "PINNUMBER":
      this.PINNUMBER = parseInt(data[1]);
      break;
    case "PINNAME":
      this.PINNAME = (data[1] == "YES");
      break;
    case "LENGTH":
      this.LENGTH = AdjustLength(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PADNAME":
      this.PADNAME = data[1];
      break;
    case "ROTATION":
      this.ROTATION = parseFloat(data[1]);
      break;
    case "FUNCTION":
      this.FUNCTION = AdjustPinFunction(parseInt(data[1]));
      break;
    case "SWAP":
      this.SWAP = parseInt(data[1]);
      break;
    case "INV":
      this.INV = (data[1] == "YES");
      break;
    case "CLOCK":
      this.CLOCK = (data[1] == "YES");
      break;
    case "SHOWNUMBER":
      this.SHOWNUMBER = (data[1] == "YES");
      break;
    case "REF":
      this.REF = (data[1] == "YES");
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Line(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "X2":
      this.X2 = AdjustCoordX(data[1]);
      break;
    case "Y2":
      this.Y2 = AdjustCoordY(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "DASHED":
      this.DASHED = AdjustLineDashed(parseInt(data[1]));
      break;
    case "ROUNDED":
      this.ROUNDED = (data[1] == "YES");
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Triangle(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "X2":
      this.X2 = AdjustCoordX(data[1]);
      break;
    case "Y2":
      this.Y2 = AdjustCoordY(data[1]);
      break;
    case "X3":
      this.X3 = AdjustCoordX(data[1]);
      break;
    case "Y3":
      this.Y3 = AdjustCoordY(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Rectangle(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "HEIGHT":
      this.HEIGHT = AdjustLength(data[1]);
      break;
    case "ROTATION":
      this.ROTATION = parseFloat(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Polygon(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "NODES":
      this.NODES = parseInt(data[1]);
      for (var i = 0; i < this.NODES; i++)
        this.pointsList[i] = new DlxPoint();
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    default:
      var index = data[0].substring(1)-1;
      switch (data[0].charAt(0))
      {
      case 'X':
        this.pointsList[index].x = AdjustCoordX(data[1]);
        break; 
      case 'Y':
        this.pointsList[index].y = AdjustCoordY(data[1]);
        break; 
      };
    }
  }
}

function Fill_Arc(item)
{
   var data = item.split("=");
   if (data.length == 2)
   {
     switch (data[0])
     {
     case "XM":
       this.XM = AdjustCoordX(data[1]);
       break;
     case "YM":
       this.YM = AdjustCoordY(data[1]);
       break;
     case "X1":
       this.X1 = AdjustCoordX(data[1]);
       break;
     case "Y1":
       this.Y1 = AdjustCoordY(data[1]);
       break;
     case "X2":
       this.X2 = AdjustCoordX(data[1]);
       break;
     case "Y2":
       this.Y2 = AdjustCoordY(data[1]);
       break;
     case "RADIUS":
       this.RADIUS = AdjustLength(data[1]);
       break;
     case "WIDTH":
       this.WIDTH = AdjustLength(data[1]);
       break;
     case "START":
       this.START = parseFloat(data[1]);
       break;
     case "END":
       this.END = parseFloat(data[1]);
       break;
     case "DASHED":
       this.DASHED = AdjustLineDashed((data[1] == "YES") ? 2 : 0);
       break;
     case "ROUNDED":
       this.ROUNDED = (data[1] == "YES");
       break;
     case "LAYER":
       this.LAYER = parseInt(data[1]);
       break;
     case "PROPERTIES":
       this.PROPERTIES = parseInt(data[1]);
       break;
    }
  }
}

function Fill_Disk(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "XM":
      this.XM = AdjustCoordX(data[1]);
      break;
    case "YM":
      this.YM = AdjustCoordY(data[1]);
      break;
    case "RADIUS":
      this.RADIUS = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Spline(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "X2":
      this.X2 = AdjustCoordX(data[1]);
      break;
    case "Y2":
      this.Y2 = AdjustCoordY(data[1]);
      break;
    case "XA":
      this.XA = AdjustCoordX(data[1]);
      break;
    case "YA":
      this.YA = AdjustCoordY(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Fill_Text(item)
{
  var data = item.split("=");
  if (data.length == 2)
  {
    switch (data[0])
    {
    case "CONTENT":
      this.CONTENT = data[1];
      break;
    case "X1":
      this.X1 = AdjustCoordX(data[1]);
      break;
    case "Y1":
      this.Y1 = AdjustCoordY(data[1]);
      break;
    case "WIDTH":
      this.WIDTH = AdjustLength(data[1]);
      break;
    case "HEIGHT":
      this.HEIGHT = AdjustLength(data[1]);
      break;
    case "LAYER":
      this.LAYER = parseInt(data[1]);
      break;
    case "WEIGHT":
      this.WEIGHT = parseInt(data[1]);
      break;
    case "ITALIC":
      this.ITALIC = (data[1] == "YES");
      break;
    case "RIGHT":
      this.RIGHT = (data[1] == "YES");
      break;
    case "FUNCTION":
      this.FUNCTION = parseInt(data[1]);
      break;
    case "HIDE":
      this.HIDE = (data[1] == "YES");
      break;
    case "ROTATION":
      this.ROTATION = parseFloat(data[1]);
      break;
    case "DYN":
      this.DYN = (data[1] == "YES");
      break;
    case "MIRR":
      this.MIRR = (data[1] == "YES");
      break;
    case "FONT":
      this.FONT = data[1];
      break;
    case "GERMAN":
      this.GERMAN = data[1];
      break;
    case "ENGLISH":
      this.ENGLISH = data[1];
      break;
    case "FRENCH":
      this.FRENCH = data[1];
      break;
    case "PROPERTIES":
      this.PROPERTIES = parseInt(data[1]);
      break;
    }
  }
}

function Read_Component(cxfFile, fields)
{
  currentComponent = new item_Component();
  // read header
  fields.forEach(Fill_Component, currentComponent);
  DlxApp.Printf("Read Component %s", currentComponent.NAME); 
  // read properties
  currentComponent.propertiesList = [currentComponent.PROPERTIES];
  for (var i = 0; i < currentComponent.PROPERTIES; i++)
    currentComponent.propertiesList[i] = cxfFile.ReadLine();
}

function Read_Package(cxfFile, fields)
{
  currentComponent.readingSymbol = false;
  currentComponent.currentItem = currentComponent.package;
  // read header
  fields.forEach(Fill_Package, currentComponent.package);
  // read properties
  currentComponent.package.propertiesList = [currentComponent.package.PROPERTIES]
  for (var i = 0; i < currentComponent.package.PROPERTIES; i++)
    currentComponent.package.propertiesList[i] = cxfFile.ReadLine();
}

function Read_Symbol(cxfFile, fields)
{
  var symbol = new item_Symbol();
  currentComponent.currentItem = symbol;
  currentComponent.readingSymbol = true;
  currentComponent.symbolsList.push(symbol);
  // read header
  fields.forEach(Fill_Symbol, symbol);
  // read properties
  symbol.propertiesList = [symbol.PROPERTIES]
  for (var i = 0; i < symbol.PROPERTIES; i++)
    symbol.propertiesList[i] = cxfFile.ReadLine();
}

function Read_Text(cxfFile, fields)
{
  var item = new item_Text();
  // read header
  fields.forEach(Fill_Text, item);
  // read properties
  item.propertiesList = [item.PROPERTIES]
  for (var i = 0; i < item.PROPERTIES; i++)
  item.propertiesList[i] = cxfFile.ReadLine();
  // Text with function 5 indicates the name of the pins
  if (item.FUNCTION == 5)
  {
    // Copy the pin name in the previous item
    if (currentComponent.currentItem.primitives.length > 0)
    {
      currentComponent.currentItem.primitives[currentComponent.currentItem.primitives.length-1].PINNAME = item.CONTENT;
      currentComponent.currentItem.primitives[currentComponent.currentItem.primitives.length-1].PINHIDE = item.HIDE;
    }
    return;
  }
  currentComponent.currentItem.primitives.push(item);
}

function Read_Item(cxfFile, fields, item, fillFunction)
{
  currentComponent.currentItem.primitives.push(item);
  // read header
  fields.forEach(fillFunction, item);
  // read properties
  item.propertiesList = [item.PROPERTIES]
  for (var i = 0; i < item.PROPERTIES; i++)
    item.propertiesList[i] = cxfFile.ReadLine();
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function BuildComponent()
{
  if (currentComponent.NAME.length == 0)
    return;
  if (currentComponent.symbolsList.length == 0)
    return;

  importedComponents++;

  var device = deviceFolder.AddDevice(currentComponent.NAME);
  device.SetDeviceName(currentComponent.NAME);
  device.SetReferencePrefix(currentComponent.PREFIX);

  // Add properties
  for (var i = 0; i < currentComponent.propertiesList.length; i++)
  {
    var data = currentComponent.propertiesList[i].split("=");
    if (data[1].length > 0)
    {
      switch (data[0])
      {
      case "MFR_NAME":
      case "MANUFACTURER":
        device.SetManufacturer(data[1]);
        break
      case "DATASHEET":
        device.SetDatasheetLink(data[1]);
        break
      default:
        device.SetAttribute(data[0], "DEVICE", data[1]); 
      }
    }
  }

  // Add Symbol
  var symbolName = currentComponent.NAME;
  device.BeginSymbolDefinition(symbolName);
  for (var i = 0; i < currentComponent.symbolsList.length; i++)
    BuildSymbol(currentComponent.symbolsList[i], i, device);
  device.EndSymbolDefinition();

  // Add footprint
  BuildFootprint(currentComponent.package, device); 
}

function BuildFootprint(pack, device)
{
  var page = footprintsDoc.NewPage("Footprints", -1, true);
  if (!page.LoadLayerStack("footprints library layer stack.clxlys"))
  {
    DlxApp.Printf("footprints library layer stack not found.");
    return;
  }

  // Get layers
  var context = new Context();
  context.doc = footprintsDoc;
  context.page = page;
  context.device = device;
  context.bIsPackage = true;
  context.layerSymbols = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPSILK);
  context.layerLIBRARYFRAMES = page.GetLayerFromType(DlxApp.LAYERTYPE_LIBRARYFRAMES);
  context.layerTOPCOPPER = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPCOPPER);
  context.layerTOPRESISTMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPRESISTMASK);
  context.layerBOTRESISTMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMRESISTMASK);
  context.layerTOPPASTEMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPPASTEMASK);
  context.layerBOTPASTEMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMPASTEMASK);
  context.layerTOPGLUE = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPGLUE);
  context.layerBOTGLUE = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMGLUE);
  context.layerTOPSILK = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPSILK);
  context.layerBOTSILK = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMSILK);
  context.layerTOPCOURTYARD = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPCOURTYARD);
  context.layerBOTCOURTYARD = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMCOURTYARD);
  context.layerTOPINFO = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPINFO);
  context.layerTOPGOLDMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPGOLDMASK);
  context.layerBOTGOLDMASK = page.GetLayerFromType(DlxApp.LAYERTYPE_BOTTOMGOLDMASK);
  context.layerKEEPOUT = page.GetLayerFromType(DlxApp.LAYERTYPE_KEEPOUT);
  context.layerTOPMECHANICAL = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPMECHANICAL);
  context.layerTOPASSEMBLY = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPASSEMBLY);
  if (!context.layerTOPCOPPER.IsValid() || !context.layerTOPSILK.IsValid())
  {
    DlxApp.Printf("Invalid footprints layer stack");
    return;
  }

  // Turn off undo registrations.
  page.EnableUndo(false);

  // Draw the frame
  page.DrawFrame(new DlxRect(10,10,200,290), 1, pack.NAME, "");
  page.DrawHotspot(hotspotPoint);

  // Draw the footprint
  for (var i = 0; i < pack.primitives.length; i++)
    pack.primitives[i].Build(context);

  // Turn on undo registrations.
  page.EnableUndo(true);

  // Add the footprint in the component
  device.AddFootprint(pack.NAME);
}

function BuildSymbol(symbol, partNumber, device)
{
  var page = symbolsDoc.NewPage("Symbols", -1, true);
  if (!page.LoadLayerStack("symbols library layer stack.clxlys"))
  {
    DlxApp.Printf("Symbols library layer stack not found.");
    return;
  }
  page.SelectView("Default View");

  // Get layers
  var context = new Context();
  context.doc = symbolsDoc;
  context.page = page;
  context.device = device;
  context.bIsPackage = false;
  context.layerSymbols = page.GetLayerFromType(DlxApp.LAYERTYPE_DRAWING);
  context.layerLIBRARYFRAMES = page.GetLayerFromType(DlxApp.LAYERTYPE_LIBRARYFRAMES);
  if (!context.layerLIBRARYFRAMES.IsValid() || !context.layerSymbols.IsValid())
  {
    DlxApp.Printf("Invalid Symbols layer stack.");
    return;
  }

  var symbolPartName = currentComponent.NAME;
  if (currentComponent.symbolsList.length > 1)
  symbolPartName = currentComponent.NAME + "_Part" + (partNumber+1) + "OF" + currentComponent.symbolsList.length;

  // Turn off undo registrations.
  page.EnableUndo(false);

  // Draw the frame
  context.layerLIBRARYFRAMES.DrawFrame(new DlxRect(10,10,200,290), 1, symbolPartName, "");

  // Add new section
  device.AddSymbolSection(symbolPartName);

  // Draw the symbol
  for (var i = 0; i < symbol.primitives.length; i++)
    symbol.primitives[i].Build(context);

  // Turn on undo registrations.
  page.EnableUndo(true);
}

function BuildItem_Pad(context)
{
  var padstyle = new DlxPadStyle();
  switch (this.FORM)
  {
  case 0: // round
    padstyle.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_ROUND, this.HEIGHT, this.WIDTH);
    break;
  case 1: // octagonal
    padstyle.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_SQUARE, this.HEIGHT, this.WIDTH, 0.5);
    break;
  case 2: // rectangular
    padstyle.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_ROUNDED, this.HEIGHT, this.WIDTH, this.ROUNDED/100);
    break;
  case 3: // oblong
    padstyle.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_ROUNDED, this.HEIGHT, this.WIDTH, 1.0);
    break;
  case 4: // polygonal
    if (this.PROPERTIES > 0)
    {
      var polygonPoints = "";
      var data = this.propertiesList[0].split("=");
      if ((data.length == 2) && (data[0] == "POLY_PAD"))
      {
        var pointsList = data[1].split(";");
        for (var i = 0; i < pointsList.length; i++)
        {
          var xy = pointsList[i].split(",");
          polygonPoints += "("+AdjustLength(xy[0])+","+AdjustLength(xy[1])+")";
        }
        padstyle.SetCustomShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, 0, 0, polygonPoints);
      }
    }; break;
  }
  if (this.LONG > 0)
    this.LONG -= this.DRILL;
  padstyle.SetHole(this.DRILL, true, -this.LONG/2, 0, this.LONG, 0);
  switch (this.STOP)
  {
  case 0: // standard
    padstyle.SetSolderMask(DlxApp.SOLDERMASK_STANDARD);
    break;
  case 1: // pad completly free
    padstyle.SetSolderMask(DlxApp.SOLDERMASK_FREE);
    break;
  case 2: // only drill hole free
    padstyle.SetSolderMask(DlxApp.SOLDERMASK_FREEHOLE);
    break;
  case 3: // pad completely covered
    padstyle.SetSolderMask(DlxApp.SOLDERMASK_COVERED);
    break;
  }
  switch (this.PASTE)
  {
  case 0: // standard
    padstyle.SetPasteMask(DlxApp.PASTEMASK_STANDARD);
    break;
  case 1: // pad covered with paste
    padstyle.SetPasteMask(DlxApp.PASTEMASK_COVERED);
    break;
  case 2: // no paste
    padstyle.SetPasteMask(DlxApp.PASTEMASK_FREE);
    break;
  }
  if (this.DRILL > 0)
    context.page.DrawTHPad(new DlxPoint(this.XM, this.YM), padstyle, this.PADNAME.length > 0 ? this.PADNAME : this.PINNUMBER.toString(), this.ROTATION);
  else context.layerTOPCOPPER.DrawPad(new DlxPoint(this.XM, this.YM), padstyle, this.PADNAME.length > 0 ? this.PADNAME : this.PINNUMBER.toString(), this.PADNAME.length > 0 ? this.PADNAME : this.PINNUMBER.toString(), this.ROTATION);
}

function BuildItem_Pin(context)
{
  var pinstyle = new DlxPinStyle(DlxApp.PINSTYLE_LINE);
  var pinNum = this.PADNAME.length > 0 ? this.PADNAME : this.PINNUMBER.toString();
  var pinFlags = DlxApp.PINFLAGS_SHOWLINE|DlxApp.PINFLAGS_VNUM|DlxApp.PINFLAGS_VNAME|DlxApp.PINFLAGS_UPDATETEXT|(this.SHOWNUMBER ? DlxApp.PINFLAGS_SHOWNUM : 0)|(this.PINHIDE ? DlxApp.PINFLAGS_HIDDEN : 0);
  context.layerSymbols.DrawPin(new DlxPoint(this.X1, this.Y1).CirclePoint(this.LENGTH, this.ROTATION), this.LENGTH, this.ROTATION+180, pinNum, this.PINNAME, "", this.FUNCTION, pinstyle, pinFlags,
  DlxApp.IEEESYMBOLINSIDE_NONE, this.CLOCK ? DlxApp.IEEESYMBOLINSIDEEDGE_CLOCK : DlxApp.IEEESYMBOLINSIDEEDGE_NONE, this.INV ? DlxApp.IEEESYMBOLOUTSIDEEDGE_DOT : DlxApp.IEEESYMBOLOUTSIDEEDGE_NONE, DlxApp.IEEESYMBOLOUTSIDE_NONE);
  // Add pin in symbol section
  context.device.AddSymbolSectionPin(pinNum, pinNum, this.PINNAME, this.FUNCTION, this.PINHIDE);
}

function BuildItem_Line(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  context.SetPenStyle(layer, new DlxPenStyle(this.WIDTH, DlxApp.STYLE_BYLAYER, new DlxDashStyle(this.DASHED), this.ROUNDED ? "ROUND" : "SQUARE", this.ROUNDED ? "ROUND" : "SQUARE"));
  layer.DrawLine(new DlxPoint(this.X1, this.Y1), new DlxPoint(this.X2, this.Y2));
}

function BuildItem_Arc(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  var center = new DlxPoint(this.XM, this.YM);
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_NULL));
  context.SetPenStyle(layer, new DlxPenStyle(this.WIDTH, DlxApp.STYLE_BYLAYER, new DlxDashStyle(this.DASHED), this.ROUNDED ? "ROUND" : "SQUARE", this.ROUNDED ? "ROUND" : "SQUARE"));
  layer.DrawEllipse(center, this.RADIUS, this.RADIUS, this.START, this.END, 0, DlxApp.ELLIPSE_CCW);
}

function BuildItem_Spline(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  var center = new DlxPoint(this.XM, this.YM);
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_NULL));
  context.SetPenStyle(layer, new DlxPenStyle(this.WIDTH, DlxApp.STYLE_BYLAYER));
  layer.DrawBezier(new DlxPoint(this.X1, this.Y1), new DlxPoint(this.XA, this.YA), new DlxPoint(this.XA, this.YA), new DlxPoint(this.X2, this.Y2));
}

function BuildItem_Text(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  switch (this.FUNCTION)
  {
  case 0: // normal text
    var font = new DlxFontStyle(this.FONT, this.HEIGHT, this.ITALIC ? DlxApp.FONTSTYLE_ITALIC : DlxApp.FONTSTYLE_REGULAR, DlxApp.FONTUNIT_MILLIMETER);
    var style = new DlxTextStyle(font, "BLACK");
    context.doc.SetStyle(style);
    layer.DrawText(new DlxPoint(this.X1, this.Y1), this.CONTENT, this.ROTATION, this.RIGHT ? DlxApp.TEXTALIGN_BOTTOMRIGHT : DlxApp.TEXTALIGN_BOTTOMLEFT, this.MIRR ? DlxApp.TEXTFLAGS_MIRRORX : 0);
    break;
  case 1: // component name
    context.layerSymbols.DrawReference(new DlxPoint(this.X1, this.Y1), this.CONTENT, this.ROTATION, this.RIGHT ? DlxApp.TEXTALIGN_BOTTOMRIGHT : DlxApp.TEXTALIGN_BOTTOMLEFT);
    if ((context.bIsPackage) && (context.layerTOPASSEMBLY !== null))
      // Replicates the reference on the TopAssembly layer. Use an attribute with the field code. 
      context.layerTOPASSEMBLY.DrawAttribute(new DlxPoint(this.X1, this.Y1), "Ref", "", "$REFERENCE", this.ROTATION, this.RIGHT ? DlxApp.TEXTALIGN_BOTTOMRIGHT : DlxApp.TEXTALIGN_BOTTOMLEFT);
    break;
  case 2: // component value
    context.layerSymbols.DrawValue(new DlxPoint(this.X1, this.Y1), this.CONTENT, this.ROTATION, this.RIGHT ? DlxApp.TEXTALIGN_BOTTOMRIGHT : DlxApp.TEXTALIGN_BOTTOMLEFT);
    break;
  }
}

function BuildItem_Triangle(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  var shapeDef = "V"+this.X1+","+this.Y1+";V"+this.X2+","+this.Y2+";V"+this.X3+","+this.Y3+";#;";
  context.doc.SetStyle(new DlxPenStyle(DlxApp.STYLE_NULL))
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_BYLAYER));
  switch (layer.GetType())
  {
  case DlxApp.LAYERTYPE_TOPCOPPER:
    layer.DrawCopper(shapeDef);
    break;
  case DlxApp.LAYERTYPE_TOPCOURTYARD:
    layer.DrawCourtyard(shapeDef);
    break;
  default:
    layer.DrawShape(shapeDef);
  }
}

function BuildItem_Rectangle(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  var rect = new DlxRect(this.X1, this.Y1, this.X1+this.WIDTH, this.Y1+this.HEIGHT);
  context.doc.SetStyle(new DlxPenStyle(DlxApp.STYLE_NULL))
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_BYLAYER));
  switch (layer.GetType())
  {
  case DlxApp.LAYERTYPE_TOPCOPPER:
    layer.DrawCopper(rect, this.ROTATION);
    break;
  case DlxApp.LAYERTYPE_TOPCOURTYARD:
    layer.DrawCourtyard(rect, this.ROTATION);
    break;
  default:
    layer.DrawRectangle(rect, this.ROTATION);
  }
}

function BuildItem_Polygon(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  context.doc.SetStyle(new DlxPenStyle(DlxApp.STYLE_NULL))
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_BYLAYER));
  switch (layer.GetType())
  {
  case DlxApp.LAYERTYPE_TOPCOPPER:
    layer.DrawCopper(this.pointsList);
    break;
  case DlxApp.LAYERTYPE_TOPCOURTYARD:
    layer.DrawCourtyard(this.pointsList);
    break;
  default:
    layer.DrawPolygon(this.pointsList);
  }
}

function BuildItem_Disk(context)
{
  var layer = context.AdjustLayer(this.LAYER);
  if (layer === null)
    return;
  var center = new DlxPoint(this.XM, this.YM);
  context.doc.SetStyle(new DlxPenStyle(DlxApp.STYLE_NULL))
  context.doc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_BYLAYER));
  switch (layer.GetType())
  {
  case DlxApp.LAYERTYPE_TOPCOPPER:
    layer.DrawCopper(center, this.RADIUS);
    break;
  case DlxApp.LAYERTYPE_TOPCOURTYARD:
    layer.DrawCourtyard(center, this.RADIUS);
    break;
  default:
    layer.DrawEllipse(center, this.RADIUS);
  }
}

See also