copy objects from one IODBLayer to another

Hello,

sometimes you want to copy objects from one layer to another layer. The simplest way to do that is to go through all objects and create new objects on the other layer.
Here is the important part for IODBLayers to copy the objects:

IFilter filter = new IFilter(window);
IODBLayer IDOBLayerOrg = (IODBLayer)step.GetLayer(originalLyrName);
IODBLayer lODBLayerNew = (IODBLayer)step.GetLayer(newLyrName);

if (IDOBLayerOrg is IODBLayer)
{
Dictionary ShapeIndexOldNew = new Dictionary(); //set new shape index if symbol is created.

foreach (IODBObject obj in IDOBLayerOrg.GetAllLayerObjects())
{
IODBObject objNew = null;
IObjectSpecificsD spec = obj.GetSpecificsD();
switch (obj.Type)
{
case IObjectType.Arc:
objNew = filter.CreateArc(lODBLayerNew);
if (!ShapeIndexOldNew.ContainsKey(((IArcSpecificsD)spec).ShapeIndex))
{
int indexNew = IFilter.AddToolFromODBString(lODBLayerNew, ((IArcSpecificsD)spec).ODBSymbol_String);
ShapeIndexOldNew.Add(((IArcSpecificsD)spec).ShapeIndex, indexNew);
}
((IArcSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IArcSpecificsD)spec).ShapeIndex];
break;
case IObjectType.Line:
objNew = filter.CreateLine(lODBLayerNew);
if (!ShapeIndexOldNew.ContainsKey(((ILineSpecificsD)spec).ShapeIndex))
{
int indexNew = IFilter.AddToolFromODBString(lODBLayerNew, ((ILineSpecificsD)spec).ODBSymbol_String);
ShapeIndexOldNew.Add(((ILineSpecificsD)spec).ShapeIndex, indexNew);
}
((ILineSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((ILineSpecificsD)spec).ShapeIndex];
break;
case IObjectType.Pad:
objNew = filter.CreatePad(lODBLayerNew);
if (!ShapeIndexOldNew.ContainsKey(((IPadSpecificsD)spec).ShapeIndex))
{
IFilter.ToolDefinition toolDef = filter.GetSymbolByShapeIndex(((IPadSpecificsD)spec).ShapeIndex,(IODBLayer) IDOBLayerOrg);
int indexNew = -1;
if (toolDef.Type == PCBI.Symbol_Type.special)
{
indexNew = IFilter.AddToolDefinitionSpecial(lODBLayerNew, (IODBLayer)IDOBLayerOrg, toolDef.ShapeIndex);
}
else
{
indexNew = IFilter.AddToolFromODBString(lODBLayerNew, ((IPadSpecificsD)spec).ODBSymbol_String);
}
ShapeIndexOldNew.Add(((IPadSpecificsD)spec).ShapeIndex, indexNew);
}
((IPadSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IPadSpecificsD)spec).ShapeIndex];
break;
case IObjectType.Surface:
objNew = filter.CreatePolygon(lODBLayerNew);
break;
case IObjectType.Text:
objNew = filter.CreateText(lODBLayerNew);
break;
default:
System.Diagnostics.Debug.WriteLine("Case not possible!");
break;
}

if(objNew!= null)
objNew.SetSpecifics(spec);
}
}
else
System.Diagnostics.Debug.WriteLine("Not implemented for components!");

As always let us know if you do not understand the example or if you need an update with special actions.

Regards
Fabio

Forums: 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.