
! script name: pksurfaces.d/pknsectiongrid
! solids: nurb surface sheet body through a grid of points

!A
!A NAME:
!A
!A 	Sheet Body: Nurb Surface Section Grid
!A
!A DESCRIPTION:
!A
!A 	This script will construct a NURBS surface through a grid of sections.
!A 	Each section must have four sides which intersect in 3D space and the
!A 	sections must be adjoining.  The rows and columns of the sections
!A 	must be picked in the proper order.
!A
!A~ image location - images/pksectiongrid.gif
!A
!B INSTRUCTIONS:
!B
!B 	NUMBER SECTIONS PER ROW: Enter the number of sections.
!B
!B 	NUMBER OF ROWS OF SECTIONS: Enter the number of rows of sections.
!B
!B 	ROW #  SECTION # : Pick the row corresponding to its description.
!B 		The order of the picks are important.
!B
!B
!B 	COLUMN #  SECTION # : Pick the column corresponding to its
!B 		description.  The order of the picks are important.
!B
!B 	ROW PATCH WIDTH: Enter the patch width to be used for the rows.
!B 		( The row corresponds to the U patch. )
!B
!B 	COLUMN PATCH WIDTH: Enter the patch width to be used for the columns.
!B 		( The column corresponds to the V patch. )
!B
!C NOTES:
!C
!C 	Problems may occur from over patching.  Avoid over patching by giving
!C 	patch widths appropriate to the sections.  Remember, the patch widths
!C 	for U and V do not have to be the same.  When a point is used for a
!C 	section, the patches converge at that point.  The point may not be in
!C 	the center of any rows or columns, the point must either be the start
!C 	or end of the row or column.
!C
!C 	NURBS are influenced by cross sections, but may not actually pass
!C 	through all of the cross sections.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: nurb section grid ")

DIM Answer$[256]
DIM Destination$[256]
DIM Rows$[256]
DIM Cols$[256]
DEG

ActivateUndo
Stat= GLPlotOn
Bezier_surf= WsFalse
IF ARGC<2 THEN
        Bezier_surf= WsFalse
ELSE
        Bezier_surf= VAL(ARGV(1))
END IF

Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)

Row_width=Patch_width
Col_width=Patch_width

Group_loop:!

Point_loop:!
Stat=SetInputFormat("n0","")
Ncols=GetValue("NUMBER SECTIONS PER ROW",Answer$)
IF ExitScript(Destination$) THEN Leave
Ncols=Ncols+1

Nrows=GetValue("NUMBER OF ROWS OF SECTIONS",Answer$)
IF ExitScript(Destination$) THEN Leave

IF Nrows<2 THEN Group_loop
IF Ncols<2 THEN Group_loop

Row_group=CreateGroup("ROW GROUP")
Pt_group=CreateGroup("POINT GROUP")
FOR I=1 TO Nrows
	Rows$=" ROW "&VAL$(I)
	FOR J=1 TO Ncols-1
		Cols$=" SECTION "&VAL$(J)
		Stat=SetInputFormat("n0","")
		Stat=SetPickMask(WsPickNoSurf)
		Path=PickGroupEnt(Rows$&":  PICK"&Cols$,0,Answer$)
		IF ExitScript(Destination$) THEN Leave
		Stat=AddToGroup(Row_group,Path)
	NEXT J
NEXT I

Col_group=CreateGroup("COLUMN GROUP")
FOR I=1 TO Ncols
	Cols$=" COLUMN "&VAL$(I)
	FOR J=1 TO Nrows-1
		Rows$=" SECTION "&VAL$(J)
		Stat=SetInputFormat("n0","")
		Stat=SetPickMask(WsPickNoSurf)
		Path=PickGroupEnt(Cols$&":  PICK"&Rows$,0,Answer$)
		IF ExitScript(Destination$) THEN Leave
		Stat=AddToGroup(Col_group,Path)
	NEXT J
NEXT I


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Row_width)
Row_width=GetValue("ROW PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Col_width)
Col_width=GetValue("COLUMN PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

WPKClearErrorFlag
Pkbody=WPKSectionGrid(WsNurbSurfEnt,Row_group,Col_group,Nrows,Ncols,Row_width,Col_width,Bezier_surf)

ActivateUndo
Stat= AdvanceUndoNumber("section grid sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

Stat=DeleteEntity(Row_group)
Stat=DeleteEntity(Col_group)
IF ValidGeometry(Pt_group) THEN
        Stat=DeleteGroup(Pt_group,1)
END IF

Leave:!
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Row_group)
Stat=DeleteEntity(Col_group)
IF ValidGeometry(Pt_group) THEN
        Stat=DeleteGroup(Pt_group,1)
END IF
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

