home *** CD-ROM | disk | FTP | other *** search
- -- 22-Feb-88 NEHolt; Created - UPL 3.0 demo program
- --
- -- --------------------------------------- HIDEINTR.UPL ------------
- -- PURPOSE: Hide the intersection of two LINES. The first digitized
- -- line remains solid, all LINES digitized after the first will be
- -- broken and trimed back at each line's intersection point with the
- -- first line. The trim distance is set at 0.0625 inches (db units).
-
- -- This program illustrates how to READ an entity's subrecord data.
- -- It shows how to create a new entity, WRITE and MODIFY subrecord
- -- data, and generate or repaint entity graphics.
-
- PROC MAIN
-
- INTEGER SMib(1),HMib(6000),i,ierr,Ngot,MibData(8),Aray(5)
- INTEGER NewMib
- COORD SCoor(2),HCoor(2),Pnt1,Pnt2
- REAL MainLen,L1,L2,TrimDist,ThisLen
-
- -- * * * start of executable code * * *
- BREAK_CHAR = 3 -- set up CTRL-C in case of abort (^C=ASCII 003)
- TrimDist=0.0625 -- set TRIM distance
- EntMask(1) -- only allow LINE entities to be digitized (type=1)
-
- -- G E T M A I N L I N E
- Print 'Digitize main line (to remain unbroken) :',
- GetEnt(1,Ngot,SMib(1),i);
- if Ngot<>1 then goto NoMore;endif -- quit if nothing digitized
-
- -- Get endpoints of digitized LINE entity. They are in the LINE's
- -- "XZ" subrecord.
- RSubrecXZ(SMib(1),1,ierr,SCoor(1),SCoor(2))
- if ierr<>0 then goto NoMore;endif -- quit if some kind of problem
- MainLen=vlen(SCoor(1),SCoor(2)) -- calc length for later use
-
- -- G E T L I N E S T O H I D E
- Print;Print 'Digitize lines to hide :',
- GetEnt(6000,Ngot,HMib(1),i); -- get MIB nums of digitized ents
- if Ngot<1 then goto NoMore;endif -- quit if none digitized
- -- Process each digitized line.
- loop i=1 to Ngot
- if HMib(i)=SMib(1) then goto DownHere;endif -- skip main line
- -- Get endpoints of line. Check if intersects with main line
- RSubrecXZ(HMib(i),1,ierr,HCoor(1),HCoor(2))
- if ierr=0 then
- -- Look for intersection point of this line with main line
- LinIntOf(SCoor(1),SCoor(2),HCoor(1),HCoor(2),Pnt1,Pnt2)
- -- reject if no intersection in 3-D space (Pnt1=Pnt2)
- if vlen(Pnt1,Pnt2)<0.01 then
- -- Instersect in 3-D space. Make sure intersection point is
- -- on the first line and not beyond either end of it. Calc
- -- dist from intersection point to either end of main line.
- -- If either distance is greater than line length then
- -- intersection point must lie beyond physical end of line.
-
- if vlen(Pnt1,SCoor(1)) <= MainLen+TrimDist/4.0 then
- if vlen(Pnt1,SCoor(2)) <= MainLen+TrimDist/4.0 then
- -- Make sure intersection point is on the second line
- -- and not beyond either end of it.
- ThisLen=vlen(HCoor(1),HCoor(2))+TrimDist
- if vlen(Pnt1,HCoor(1)) > ThisLen then goto DownHere;endif
- if vlen(Pnt1,HCoor(2)) > ThisLen then goto DownHere;endif
- -- They do intersect, okay to continue.
- -- B R E A K T H I S L I N E
- -- Determine length of each segment of broken line.
- L1=vlen(HCoor(1),Pnt1)
- L2=vlen(HCoor(2),Pnt1)
- -- M O D I F Y F I R S T S E G M E N T
- -- Shorten existing line. Adjust one of its end points.
- -- This will be one segment of the broken line.
- if L1 > TrimDist then
- -- Calculate new end point of the line.
- Pnt2.x=HCoor(1).x+((L1-TrimDist)/L1)*(Pnt1.x-HCoor(1).x)
- Pnt2.y=HCoor(1).y+((L1-TrimDist)/L1)*(Pnt1.y-HCoor(1).y)
- Pnt2.z=HCoor(1).z+((L1-TrimDist)/L1)*(Pnt1.z-HCoor(1).z)
- -- Modify line's XZ subrecord with new end point coors
- MSubrecXZ(HMib(i),1,ierr,HCoor(1),Pnt2)
- else
- Erase Ent_Id(HMib(i)) -- too short, delete it.
- endif
-
- -- C R E A T E N E W S E G M E N T
- if L2 > TrimDist then
- -- Create new LINE ent. First get COL/FONT/LAY of original.
- ReadEnt(HMib(i),MibData(1)) -- get 8 word index block
- -- Set up array to create new entity MIB index block
- Aray(1)=MibData(4) -- LAYER in 4th word
- Aray(2)=MibData(5) -- VIEW VIS in 5th word
- Aray(3)=MibData(6) -- GROUP NUMBER in 6th word
- Aray(4)=MibData(7) -- FONT in 7th word
- Aray(5)=MibData(8) -- COLOR in 8th word
- -- Create new LINE entity (type=1)
- Addent(1,Aray(1),NewMib,ierr) -- create MIB index block
- -- Add XZ line end point subrecord to new LINE entity.
- -- Calc beginning point of line and use original end pnt.
- Pnt2.x=HCoor(2).x+((L2-TrimDist)/L2)*(Pnt1.x-HCoor(2).x)
- Pnt2.y=HCoor(2).y+((L2-TrimDist)/L2)*(Pnt1.y-HCoor(2).y)
- Pnt2.z=HCoor(2).z+((L2-TrimDist)/L2)*(Pnt1.z-HCoor(2).z)
- WSubrecXZ(NewMib,ierr,Pnt2,HCoor(2)) -- add "XZ" subrecord
- -- Generate graphics for the new LINE entity
- RpntEnt(NewMib,1,ierr);
- endif
- RpntEnt(HMib(i),1,ierr); -- Repaint the original LINE
- endif
- endif
- endif
- endif
- DownHere:
- end_loop
- NoMore:
- end proc
-