Creating a solid circle

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: admin, support, SDS

Post Reply
marym
Posts: 15
Joined: 22 Jul 2015, 00:03

Creating a solid circle

Post by marym » 11 May 2018, 00:11

I created this method to create a hollow circle. How can I modify it to fill it in with color?

Code: Select all

void CadSoftToolsH::AddCircle(double xCtr, double yCtr, double radius, String LayerName, const Graphics::TColor color)
{
	TsgDXFCircle * vCircle = new TsgDXFArc();
	vCircle->Radius = radius;
	vCircle->Point = MakeFPoint(xCtr, yCtr, 0);
	vCircle->Color = color;
	vCircle->Layer = pDrawing->Converter->LayerByName(LayerName);
	if(!PlaceEntity(vCircle))
		delete vCircle;
}

bool CadSoftToolsH::PlaceEntity(TsgDXFEntity *AEntity, const AnsiString ALayoutName )
{
	bool result = false;
	TsgDXFLayout *vLayout;
	if (ALayoutName == "") {
		vLayout = pDrawing->Converter->Layouts[0];
	}
	else
		vLayout = pDrawing->Converter->LayoutByName(ALayoutName);
	if (vLayout)
	{
		pDrawing->Converter->Loads(AEntity);
		if (pDrawing->Converter->OnCreate)
			pDrawing->Converter->OnCreate(AEntity);
		vLayout->AddEntity(AEntity);
		result = true;
	}
	return result;
}

protected:
	TsgDWGImage *pDrawing;




support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Creating a solid circle

Post by support » 11 May 2018, 22:57

Hello Mary,

You can add a filling to a circle by using TsgCADCurvePolygon and Tsg2DArc objects:

Code: Select all

void CadSoftToolsH::AddFilling(TsgDXFCircle *ACircle, const Graphics::TColor AColor)
{
   Tsg2DArc *v2DArc = new Tsg2DArc();
   v2DArc->CenterPoint = MakeF2DPointFrom3D(ACircle->Point);
   v2DArc->Radius = ACircle->Radius;
   v2DArc->StartParam = 0;
   v2DArc->EndParam = 360;

   TsgCADCurvePolygon *vCADCurvePolygon = new TsgCADCurvePolygon();
   vCADCurvePolygon->AddBoundaryList(1);
   vCADCurvePolygon->BoundaryData[0]->Add(v2DArc);
   vCADCurvePolygon->Layer = ACircle->Layer;
   vCADCurvePolygon->Color = AColor;

   if (!PlaceEntity(vCADCurvePolygon))
      delete vCADCurvePolygon;
}
The purpose of the Tsg2DArc object is to replicate the circle boundary. Notice that Tsg2DArc and other Tsg2DCurve derivatives are auxiliary objects, they are not added directly to pDrawing->Converter and not visible on the drawing. Their purpose is to make up the boundary of filling or hatch.

The filling may be added right after creating a hollow circle, as follows:

Code: Select all

void CadSoftToolsH::AddCircle(double xCtr, double yCtr, double radius, String LayerName, const Graphics::TColor color)
{
   TsgDXFCircle *vCircle = new TsgDXFCircle();
   vCircle->Radius = radius;
   vCircle->Point = MakeFPoint(xCtr, yCtr, 0);
   vCircle->Color = color;
   vCircle->Layer = pDrawing->Converter->LayerByName(LayerName);

   if(!PlaceEntity(vCircle))
      delete vCircle;
   else
      AddFilling(vCircle, color);
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

marym
Posts: 15
Joined: 22 Jul 2015, 00:03

Re: Creating a solid circle

Post by marym » 14 May 2018, 16:16

Works perfectly. Thank you!

Post Reply