
! script name: surfaces.d/csectiongrid
! 3dtopic: construct a bicubic surface through a grid of sections

!A
!A NAME:
!A
!A 	Bicubic: Section Grid
!A
!A DESCRIPTION:
!A
!A 	This script will construct a bicubic surface through a grid of
!A 	sections.  Each section must have four sides which intersect in
!A 	3D space and the sections must be adjoining.  The rows and columns
!A 	of the sections must be picked in the proper order.
!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
!B 		rows of sections.
!B
!B 	ROW #  SECTION #  Point: Pick the row corresponding
!B 		to its description.  The order of the picks are important.
!B
!B 		P - This option allows the coordinates of the point to b
!B 		    entered.
!B
!B 	NOTE: The following question is only asked if "Point" was selected
!B 		in response to the previous question.
!B
!B 	INPUT ROW POINT # ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		for the point in this row.
!B
!B 	COLUMN #  SECTION #  Point: Pick the column corresponding
!B 		to its description.  The order of the picks are important.
!B
!B 		P - This option allows the coordinates of the point to b
!B 		    entered.
!B
!B 	NOTE: The following question is only asked if "Point" was selected
!B 		in response to the previous question.
!B
!B 	INPUT COLUMN POINT # ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates for the point in this column.
!B
!B 	ROW PATCH WIDTH: Enter the patch width to be used for
!B 		the rows.  ( The row corresponds to the U patch. )
!B
!B 	COLUMN PATCH WIDTH: Enter the patch width to be used
!B 		for the columns.  ( 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 at the
!C 	start or end of the row or column.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: surface grid ")

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

ActivateUndo
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("a1",",P,")
		Stat=SetPickMask(WsPickNoSurf)
		Path=PickGroupEnt(Rows$&":  PICK"&Cols$&"   Point",0,Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$="P" THEN
			RowPoint=XyzInput("INPUT ROW POINT "&VAL$(J),WsXyzInput)
			IF ExitScript(Destination$) THEN Leave
			Stat=SetLastPoint(RowPoint,WsXyzInput)
			Path=Rowpoint
			Stat=AddToGroup(Pt_group,Rowpoint)
		END IF
		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("a1",",P,")
		Stat=SetPickMask(WsPickNoSurf)
		Path=PickGroupEnt(Cols$&":  PICK"&Rows$&"   Point",0,Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$="P" THEN
			ColPoint=XyzInput("INPUT COLUMN POINT "&VAL$(J),WsXyzInput)
			IF ExitScript(Destination$) THEN Leave
			Stat=SetLastPoint(ColPoint,WsXyzInput)
			Path=Colpoint
			Stat=AddToGroup(Pt_group,Colpoint)
		END IF
		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

Surface=SectionGrid(WsCubicSurfEnt,"CUBICSURF",Row_group,Col_group,Nrows,Ncols,Row_width,Col_width)

ActivateUndo
Stat= AdvanceUndoNumber("bicubic surface")
Stat= AddItemToUndo(WsUBCreateMode,Surface)

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

Leave:!
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
