
! script name: misc.d/readsections

!A
!A NAME:
!A
!A 	READ ASCII POINT SECTIONS
!A
!A DESCRIPTION:
!A
!A 	This script reads sections from a preprocessed ascii points file.
!A
!B INSTRUCTIONS:
!B
!B	SELECT FILE: Select the ascii points file by using
!B		  the file select box. The file selected
!B		  must have been preprocessed into 
!B		  standard form. The preprocessing
!B		  is done by a special shell script for
!B		  the particular format.
!B
!B	# OF SECTIONS PER SURFACE, No surfaces: Number of sections used
!B				for each surface. Fastest results will
!B				be obtained if a relatively small number
!B				of sections are used for each surface.
!B				Using large numbers of sections per surface 
!B				will have a blending efect between the sections.
!B				Surfaces may either be Nurb or
!B				Bicubic. Nurb surfaces are recomended.
!B				Nurb surface default is set in the script.
!B				Script must be changed to output bicubics.
!B	
!B	PATCH WIDTH: Specify the patch width to be used on the surfaces.
!B		     Should be smaller then small details on the sections.
!B
!B	IF No Surfaces are requested then:
!B
!B	SECTION TYPE Chains, Splines, Points: This will determine
!B		the type of entity created for a section.
!B
!B		Chains: The sections are brought in as pointchain entities.
!B			All points are used. This is the most economical
!B			way to bring in large numbers of points.
!B			Synergy can convert pointchains to nurbs or to
!B			lines and circles.
!B			This is the recomended method.
!B
!B		Splines: The sections are brought in as nurb curves of 
!B			degree 3 (default in the script). 
!B			The Nurb curves will smooth the data. 
!B			This takes more space and time then pointchains.
!B			The digitized points are used as control points
!b			in the spline.
!B
!B		Points: All of the points are brought in as point entities.
!B			This method is very memory intensive since a
!B			separate entity is created for each point.
!B			This method is not recomended.
!B
!B
!B OPTIONS:
!B 	
!B		This script places each section on a different layer.
!B		Each surface is also put on a different layer.
!B		The layer sequence starts at the Current Layer.
!B
!B		Default surface and section colors are specified in
!B		the script.
!B
!B HINTS:	
!B		The surfaces created are only as good as the point sections.
!B		Uneven section start and endpoints will introduce wiggles
!B		into the surfaces created. Start and endpoints should
!B		be as even as possible.
!B
!B		Surfaces are created from sections by equal arc length along
!B		the section curves. 
!B
!B		Sharp corner details are not easy to digitize. It is 
!B		important that corner details are well specified
!B		by the points digitized. One problem that occurs is
!B		that neighboring sections are not consistent along
!B		sharp corners. This will introduce wiggles into 
!B		the surfaces.
!B
!B		When surfaces are created the sections are brought in as
!B		pointchain entities. Any other form is a waste of time
!B		and resources.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: readsections ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM Retrieve_dir$[255]

Reverse_sect= 1
Section_type= 1
Spline_deg= 3
Surface_color= 10
Section_color= 14
Surface_type= WsNurbSurfEnt

Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)

D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO OPEN"
Mask$="[A-Za-z0-9]*"

StdWorkplane

Start:!
Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("retrieve dir",WsSystemVars,PathNameDirectory(Answer$))
Name$= Answer$


Stat=SetInputFormat("n0a1",",N,")
Num_sect=GetValue("# OF SECTIONS PER SURFACE, No surfaces",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "N" THEN 
	No_surfaces=1

	Stat=SetInputFormat("a1",",C,S,P,")
        Stat=GetValue("SECTION TYPE Chains, Splines, Points",Answer$)
        IF ExitScript(Destination$) THEN Leave
	SELECT Answer$
	CASE "C"
		Section_type=1
	CASE "S"
		Section_type=2
	CASE "P"
		Section_type=4
	END SELECT
ELSE
	No_surfaces=0

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

END IF

Stat= SetCurrentColor(Section_color)
Layer= CurrentLayer
Group= ReadSections(Name$,Section_type,Spline_deg)
Nsections= GroupCount(Group)
FOR I= 1 TO Nsections
	Path= GroupElement(Group,I)
	Stat=LayerContour(Path,Layer)
	Stat=AutoNumberCont(Path)
	IF NOT(I MOD 2) THEN
		IF Reverse_sect THEN
			Stat= ReverseContour(Path)
		END IF
	END IF
	Layer= Layer+1
NEXT I
IF No_surfaces THEN Leave


Scount= 0
Group1= CreateGroup("TEMP")
Stat= SetCurrentColor(Surface_color)
FOR I= 1 TO Nsections
	Path= GroupElement(Group,I)
	Stat= AddToGroup(Group1,Path)
	Scount= Scount+1
	IF Scount>= Num_sect THEN
		Surf1=ArcLenBlendSurf(Surface_type,Group1,"BLEND",Patch_width)
		Stat=SetLayer(Surf1,Layer)
		Scount=0
		Stat= DeleteEntity(Group1)
		Group1= CreateGroup("TEMP")
		Stat= AddToGroup(Group1,Path)
		Scount=1
		Layer= Layer+1
	END IF
NEXT I
IF Scount> 1 THEN
	Surf1=ArcLenBlendSurf(Surface_type,Group1,"BLEND",Patch_width)
	Stat=SetLayer(Surf1,Layer)
	Stat= DeleteEntity(Group1)
END IF


Leave:!
LowerFileBox
Stat= SetCurrentColor(0)
Stat= DeleteEntity(Group1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
