
! script name: surfaces.d/nsectiongrid
! 3dtopic: nurb surface through a grid of points

!A
!A NAME:
!A
!A 	NURBS: 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
!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 # PICK SECTION, Point: Pick the row corresponding to its
!B 		description.  The order of picks are important.
!B
!B 		P - This option allows the coordinates of the point to be
!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 coordinate for the point
!B 		in this row.
!B
!B 	COLUMN # PICK ROW, Point: Pick the column corresponding to its
!B 		description.  The order of the picks are important.
!B
!B 		P - This option allows the coordinates of the point to be
!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 coordinates for the
!B 		point in this column.
!B
!B 	ROW PATCH WIDTH: Enter the patch width to be used for the rows.
!B
!B 	COLUMN PATCH WIDTH: Enter the patch width to be used for the columns.
!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

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

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

ActivateUndo
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)

Upatch=Patch_width
Vpatch=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(WsNurbSurfEnt,"",Row_group,Col_group,Nrows,Ncols,Row_width,Col_width,Bezier_surf)

ActivateUndo
Stat= AdvanceUndoNumber("nurb 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

