Add Gradient Color

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
lolena1888
Posts: 19
Joined: 03 Dec 2008, 20:04

Add Gradient Color

Post by lolena1888 » 15 Jan 2009, 18:36

Hi Sergey,
Can you please clarify how to add gradient color to the shape built with polyline? Help file is not very explanative.

The first question is adding Boundaries. Does it mean that I have to always use 2DBoundaryList to add them?
Can I add any entity as a border? And where I can find BoundaryType values?

I tryed the following code based on your examples for adding hatch (pline - existing 3D polyline)

Code: Select all

   CADGradientPolygon entGrHatch = new CADGradientPolygon ();         
         
   CAD2DBoundaryList v2DBList = new CAD2DBoundaryList();
   v2DBList.BoundaryType = 7;// Polyline type
       
  CAD2DPolyline v2DPolyline = new CAD2DPolyline();
   v2DBList.Add(v2DPolyline);
   
CAD2DPoint ent2DPoint;
   DPoint Point;
   for (int j = 0; j < pline.PolyPoints.Count; j++)
   {
       Point = (DPoint)pline.PolyPoints[j];
       ent2DPoint = new CAD2DPoint(Point.X, Point.Y);
       v2DPolyline.Vertexes.Add(ent2DPoint);
   }

   v2DPolyline.Closed = true;
   
    entGrHatch .Color = Color.Coral;
    entGrHatch .GradientColor = Color.Azure;
    entGrHatch .Boundaries.Add(v2DBList);
But the code throws an exception that the specified cast is not valid (v2DPolyline has 98 vertexes). Debug shows that the exception is raised when we add 2DPolyline to BoundaryList. Can you clarify me what is wrong?

Thanks a lot.

Elena

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

Re: Add Gradient Color

Post by support » 16 Jan 2009, 17:06

Hi Elena,

Please try the following code:

Code: Select all

		private void btnAddGradientHatch_Click(object sender, System.EventArgs e)
		{
			if(this.cadImage == null)
			{
				this.cadImage = new CADImage();
				this.cadImage.InitialNewImage();
				this.cadImage.UseDoubleBuffering = false;
			}
			this.cadImage.UseDoubleBuffering = false;

			CADCurvePolygon vGradient;
			CAD2DBoundaryList v2DBList;
			CAD2DPolyline v2DPolyline;
			CAD2DPoint vPoint2D;

			vGradient = new CADCurvePolygon();
			vGradient.GradientColor = Color.Red;
			vGradient.GradientName = "INVSPHERICAL";
			//'CURVED', 'CYLINDER', 'HEMISPHERICAL', 'LINEAR',
			//'SPHERICAL', 'INVCURVED', 'INVCYLINDER', 'INVHEMISPHERICAL', 'INVSPHERICAL'

			v2DBList = new CAD2DBoundaryList();
			v2DBList.BoundaryType = 7;// Polyline type
			vGradient.BoundaryData.Add(v2DBList);
			v2DPolyline = new CAD2DPolyline();
			v2DBList.Add(v2DPolyline);
			vPoint2D = new CAD2DPoint(0.0, 0.0);
			v2DPolyline.AddVertex(vPoint2D);
			vPoint2D = new CAD2DPoint(93.0,29.0);
			v2DPolyline.AddVertex(vPoint2D);
			vPoint2D = new CAD2DPoint(150.0, 120.0);
			v2DPolyline.AddVertex(vPoint2D);
			vPoint2D = new CAD2DPoint(0.0,0.0);
			v2DPolyline.AddVertex(vPoint2D);

			vGradient.Loaded(this.cadImage.Converter);

			this.cadImage.CurrentLayout.Entities.Add(vGradient);
			this.cadImage.Converter.OnCreate(vGradient);	
			this.ResizeLayout();
		}
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

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

Re: Add Gradient Color

Post by support » 22 Jan 2009, 09:29

Hi, Elena,

Here goes a brief description for classes which define different types of hatch.

class CADPolyPolygon - solid HATCH that has few borders.
class CADGradientPolygon: CADPolyPolygon - HATCH with gradient filling;
class CADCurvePolygon: CADGradientPolygon - solid (gradient ) HATCH that has complicated borders represented by arcs, splines etc.
class CADHatch: CADCurvePolygon - HATCH that uses the pattern.

CADPolyPolygon -> CADGradientPolygon -> CADCurvePolygon -> CADHatch

CADPolyPolygon.Boundaries - a list of lists of CAD2DPoint objects.
CADGradientPolygon.Boundaries - a list of lists of CAD2DPoint objects.
CADCurvePolygon.BoundaryData - it is a list of CAD2DBoundaryList objects. Every CAD2DBoundaryList object represents single boundary. CAD2DBoundaryList object - represents a list of CAD2DCurve (its descendants: CAD2DLine, CAD2DPolyline, CAD2DSpline, CAD2DArc, CAD2DEllipse) objects. CADCurvePolygon.Boundaries is being filled when defining borders by CADCurvePolygon.BoundaryData.
CADHatch - borders are repsectivly to CADCurvePolygon.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply