Frame

From Vectorlab
Jump to: navigation, search

Frame

Contents

export this page XML wiki

Frame is a 2D path object that draws a Frame using the undocumented OffsetPoly function. It uses a single parameter d for the offset. It is intended as starting point to do something really useful.

Frame.png

PROCEDURE Frame;
VAR
	resultStatus, OK: BOOLEAN;
	plugN: STRING;
	plugH, recordH, wallH, profileH, pathH, HDL, PolyHDL: HANDLE;
	vertexNum,vertexType,I: INTEGER;
	B,H,pX,pY,X2,Y2,arcRadius: REAL;
	
BEGIN
	
	IF GetCustomObjectInfo (plugN, plugH, recordH, wallH) THEN
	
	BEGIN
		
		pathH := GetCustomObjectPath(plugH);
		profileH := GetCustomObjectProfileGroup(plugH);
		vertexNum := GetVertNum(pathH);
		
		ClosePoly;
		BeginPoly;
			FOR I := 1 TO vertexNum DO BEGIN
				GetPolylineVertex(pathH, I, pX, pY, vertexType, arcRadius);
				AddPoint(pX, pY);
			END;
		EndPoly;
		HDL := LNewObj;
		FOR I := 1 TO vertexNum DO BEGIN
			GetPolylineVertex(pathH, I, pX, pY, vertexType, arcRadius);
			SetPolylineVertex(HDL, I, pX, pY, vertexType, arcRadius, FALSE);
		END;
		
		PolyHDL :=OffsetPoly(HDL, -pd, 1, TRUE, FALSE, 1, 1);
		
		Locus(0,0);
		HDL := LNewObj;
		OK:= SetCustomObjectProfileGroup(plugH, HDL);
		
	END;
	
END;

RUN(Frame);

Frame Plugin

This version is a little bit more sophisticated and draws an empty frame. Again a single parameter d for the frame width is needed. It will inset any given Polyline by amount d.

You can download the Frame Plugin Object from my site waso.com.

Known bugs:

  1. Outset is not possible. A negative number for d will be ignored. In order to make this to work a little more refinement is needed. In this case the handle returned by OffsetPoly is a handle directly to the polyline, not to a group. Furthermore the stacking order of the polylines needs to be reversed prior to clipping. Even then the results will not be pretty. Perhaps some tweaking with the (unknown) parameters of the offsetPoly function is needed.
  2. It would be nice to be able to draw open frames with or without end caps (just like walls).
PROCEDURE Frame;
	
	{Opensource}
	{Created by Thomas Wagensommerer on 8.2.2006 TO help starting vcor.net}
	{Improved by ......}
	
VAR
	resultStatus, OK: BOOLEAN;
	plugN: STRING;
	plugH, recordH, wallH, profileH, pathH, HDL, offsetGroupH, newPolyH, PolyH: HANDLE;
	vertexNum,vertexType,I: INTEGER;
	B,H,pX,pY,X2,Y2,arcRadius: REAL;
	
	
FUNCTION Clip(clipped,clipper:HANDLE):HANDLE;
	{Workaround FOR bug in ClipSurface}
	
VAR
	h1: HANDLE;
	objclass, actclass :STRING;
	
FUNCTION Recover:HANDLE;
	
FUNCTION Finder(h: HANDLE): BOOLEAN;
	
BEGIN
	IF GetClass(h)='Temp' THEN h1 := h;
	SetClass(h1, 'None');
END;

BEGIN
	ForEachObjectInLayer(Finder, 2, 2, 0);
	setclass(h1, objclass);
	Recover := h1;
END;

BEGIN
	objclass := GetClass(Clipped);
	actclass := ActiveClass;
	SetClass(Clipped, 'Temp');
	ClipSurface(clipped, clipper);
	Clip := Recover;
	DelClass('Temp');
	NameClass(actclass);
END;

{-- main --}

BEGIN
	
	IF GetCustomObjectInfo (plugN, plugH, recordH, wallH) THEN
	
	BEGIN
		
		pathH := GetCustomObjectPath(plugH);
		profileH := GetCustomObjectProfileGroup(plugH);
		vertexNum := GetVertNum(pathH);
		
		ClosePoly;
		
		BeginPoly;
			FOR I := 1 TO vertexNum DO BEGIN
				GetPolylineVertex(pathH, I, pX, pY, vertexType, arcRadius);
				AddPoint(pX, pY);
			END;
		EndPoly;
		polyH := LNewObj;
		FOR I := 1 TO vertexNum DO BEGIN
			GetPolylineVertex(pathH, I, pX, pY, vertexType, arcRadius);
			SetPolylineVertex(PolyH, I, pX, pY, vertexType, arcRadius, FALSE);
		END;
		
		offsetGroupH :=OffsetPoly(polyH, -Abs(pd), 1, FALSE, FALSE, 100, 1);
		{offsetGroupH is a handle TO a group, as long as the second parameter is negative}
		newPolyH := FInGroup(offsetGroupH);
		
		polyH := Clip(polyH, newPolyH);
		DelObject(newPolyH);
		
		Locus(0, 0);
		HDL := LNewObj;
		OK := SetCustomObjectProfileGroup(plugH, HDL);
		
	END;
END;
RUN(Frame);