How to add a new Layer to the Converter ?
Moderators: SDS, support, admin
How to add a new Layer to the Converter ?
Sir,
I want to add a new Layer to the TsgDXFImage->Converter.
If it is possible, Would you show me the sample code
for this work for C++Builder 6.0 ?
If you don't have c++ code, delphi code is ok.
I want to add a new Layer to the TsgDXFImage->Converter.
If it is possible, Would you show me the sample code
for this work for C++Builder 6.0 ?
If you don't have c++ code, delphi code is ok.
Hi,
Here goes code example.
Sergey.
please post questions to the forum or write to support@cadsofttools.com
Here goes code example.
Code: Select all
void <b>__fastcall</b> TfmMain::sbMergingTestClick(TObject *Sender)
{
TsgDXFImage *vGlobalCADFile;
TsgDXFImage *Im;
AnsiString cnstLayerName = "new_layer";
AnsiString cnstLTypeName = "HIDDEN";
AnsiString cnstCurDirName = "MergeFiles\\";
<b>char</b> *cnstFileNames[2] = {"Frame.dxf", "Inserted.dxf"};
<b>char</b> *N[ 8 ] = {"TABLES", "BLOCKS", "ENTITIES", "LTYPE", "LAYERS", "BLOCK_RECORD", "STYLE", "DIM_STYLE"};
TObject *vCADFiles[2];
TsgDXFLineType *vLType;
TsgDXFLine *vLine;
TsgDXFArc *vArc;
TsgDXFTable *vTbl;
<b>int</b> I;
SetCurrentDir(ExtractFilePath(Application->ExeName) + cnstCurDirName);
MacroStrings->Text = Memo1->Text;
vGlobalCADFile = <b>new</b> TsgDXFImage;
// Drawing have not border
vGlobalCADFile->IsWithoutBorder = <b>true</b>;
vGlobalCADFile->ColorToLineWeight->Add("clYellow = 0.1");
vGlobalCADFile->ColorToLineWeight->Add("clLime = 0.3");
vGlobalCADFile->ColorToLineWeight->Add("clAqua = 0.1");
vGlobalCADFile->ColorToLineWeight->Add("clBlue= 0.1");
vGlobalCADFile->ColorToLineWeight->Add("clFuchsia = 0.1");
vGlobalCADFile->ColorToLineWeight->Add("clBlack = 0.1");
vGlobalCADFile->ColorToLineWeight->Add("clGray= 0.5");
vGlobalCADFile->ColorToLineWeight->Add("clSilver= 1");
// or this: vGlobalCADFile->ColorToLineWeight->Assign(Self.memColorToLineWeight.Lines);
// Adding the new linetype to image-converter
vLType = <b>new</b> TsgDXFLineType;
vLType->Name = cnstLTypeName;
vLType->Lines->Scale = 50; // linetype scale
vLType->Lines->AddTick(0.25); // length of the "solid" part of a line
vLType->Lines->AddTick(-0.125); // length of the "empty" part of a line
<b>if</b> (vGlobalCADFile->Converter->Sections[csLTypes] == NULL)
{
vGlobalCADFile->Converter->Sections[csLTypes] = (TsgDXFGroup *)(vGlobalCADFile->Converter->NewEntity(vGlobalCADFile->Converter->Sections[csTables],__classid(TsgDXFTable)));
vGlobalCADFile->Converter->Sections[csLayers] = (TsgDXFGroup *)(vGlobalCADFile->Converter->NewEntity(vGlobalCADFile->Converter->Sections[csTables],__classid(TsgDXFTable)));
vGlobalCADFile->Converter->Main->AddEntity(vGlobalCADFile->Converter->Sections[csTables]);
vGlobalCADFile->Converter->Main->AddEntity(vGlobalCADFile->Converter->Sections[csBlocks]);
vGlobalCADFile->Converter->Main->AddEntity(vGlobalCADFile->Converter->Sections[csEntities]);
<b>for</b>(I=0;I<4;I++)
{
vTbl = (TsgDXFTable *)(vGlobalCADFile->Converter->Sections[(TConvSection)I]);
vTbl->Name = N[I];
}
}
vGlobalCADFile->Converter->Sections[csLTypes]->AddEntity(vLType);
// The first inserted file
<b>if</b> (ExtractFileExt(cnstFileNames[0]) == ".dxf")
vCADFiles[0] = <b>new</b> TsgDXFImage;
#ifdef sgDXFONLY
;
#else
<b>else</b>
vCADFiles[0] = <b>new</b> TsgDWGImage;
#endif
Im = <b>dynamic_cast</b><TsgDXFImage *>(vCADFiles[0]);
Im->LoadFromFile((AnsiString)(cnstFileNames[0]));
vGlobalCADFile->AddScaledDXF(
vCADFiles[0], // TsgDXFImage object for inserting
ChangeFileExt(ExtractFileName(cnstFileNames[0]), ""), // Name
MakeFPoint(0.0, 0.0, 0.0), // Position in ACAD coords
MakeFPoint(1, 1, 1), // Scale factor
0.0); // Rotation angle (degrees)
// The second inserted file
<b>if</b> (ExtractFileExt(cnstFileNames[1]) == ".dxf")
vCADFiles[1] = <b>new</b> TsgDXFImage;
#ifdef sgDXFONLY
;
#else
<b>else</b>
vCADFiles[1] = <b>new</b> TsgDWGImage;
#endif
Im = <b>dynamic_cast</b><TsgDXFImage *>(vCADFiles[1]);
Im->LoadFromFile((AnsiString)(cnstFileNames[1]));
vGlobalCADFile->AddScaledDXF(
vCADFiles[1], // TsgDXFImage object for inserting
ChangeFileExt(ExtractFileName(cnstFileNames[1]), ""), // Name
MakeFPoint(80.0, 100.0, 0.0), // position in ACAD coords
MakeFPoint(10, 10, 1), // scale factor
0.0); // rotation angle (degrees)
// Adding the line entity
vLine = <b>new</b> TsgDXFLine;
vLine->Point = MakeFPoint( 80, 100, 0);// first point
vLine->Point1 = MakeFPoint(150, 150, 0);// second point
vLine->SetColor(clBlue); // color
vLine->Layer = vGlobalCADFile->Converter->LayerByName(cnstLayerName);
vLine->SetLType(vGlobalCADFile->Converter->LTypeByName(cnstLTypeName));
<b>if</b> (vGlobalCADFile->Converter->OnCreate != NULL)
vGlobalCADFile->Converter->OnCreate(vLine);
vGlobalCADFile->Converter->Loads(vLine);
vGlobalCADFile->Converter->Sections[csEntities]->AddEntity(vLine);
// Adding the arc entity
vArc = new TsgDXFArc;
vArc->StartAngle = 60; // start angle in degrees
vArc->EndAngle = 210; // } angle in degrees
vArc->Radius = 50; // radius
vArc->Point = MakeFPoint( 110, 160, 0); // center point
vArc->SetColor(clBlue); // color
vArc->Layer = vGlobalCADFile->Converter->LayerByName(cnstLayerName);
vArc->SetLType(vGlobalCADFile->Converter->LTypeByName(cnstLTypeName));
<b>if</b> (vGlobalCADFile->Converter->OnCreate != NULL)
vGlobalCADFile->Converter->OnCreate(vArc);
vGlobalCADFile->Converter->Loads(vArc);
vGlobalCADFile->Converter->Sections[csEntities]->AddEntity(vArc);
// Apply new drawing extents
vGlobalCADFile->GetExtents();
// Copying of new drawing to sgPaintBox
btnLayers->Enabled = <b>true</b>;
vGlobalCADFile->IsWithoutBorder = <b>false</b>;
sgPaintBox->Picture->Graphic = vGlobalCADFile;
Img = <b>dynamic_cast</b><TsgDXFImage *>(sgPaintBox->Picture->Graphic);
sgPaintBox->Width = Ceil(vGlobalCADFile->AbsWidth());
sgPaintBox->Height = Ceil(vGlobalCADFile->AbsHeight());
sgPaintBox->Invalidate();
EnableScales();
Orbit3D->Visible = <b>false</b>;
Orbit3D->CADImage = Img;
sb3DOrbit->Enabled = <b>true</b>;
sb3DOrbit->Down = <b>false</b>;
sgPaintBox->Align = alNone;
sgPaintBox->Align = alClient;
<b>delete</b> vGlobalCADFile;
}
please post questions to the forum or write to support@cadsofttools.com