home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p115 / 10.ddi / GCD4 / UPL / INSCHAM.UPL < prev    next >
Encoding:
Text File  |  1988-01-25  |  4.6 KB  |  107 lines

  1. --INSCHAM.UPL
  2. --This UPL program implements a new GCD command via UPL to insert chamfers.
  3. --When installed in the VNP command table it will execute just like any other
  4. --GCD command.
  5. --Command syntax is:
  6. --INS CHAM [SIZe <num>] [COLor <num>] [LAYer <num>] [FONt <num>] : <get data>
  7.  
  8. proc WarnMsg(In String Msg:80)------------------------------------------------
  9. PrintWin = 12; TextColor(115)  --use warning message window and color
  10. print Msg+'#29##30#',     --the 29 and 30 codes clear and remove the window
  11. PrintWin = 1;  TextColor(106)  --return to standard window and color
  12. end proc----------------------------------------------------------------------
  13.  
  14. proc Main---------------------------------------------------------------------
  15.  
  16. const integer MaxLines = 30 , MaxLinesP1 = 31, \
  17.               CR = 13, Abort = 3, Colon = 58, Semi = 59
  18. integer MIBNums(MaxLines), TotEnts = 0, I, EType, OtherEnd, NEnts, \
  19.         NumDigs, SmallEnd, BigEnd, IEnd(MaxLines), IColor, IFont, \
  20.         ILayer
  21. coord LinEnds(2,MaxLines), NewEnd(MaxLinesP1)
  22. string Ans1:1, SVal:1
  23. real LLength, NewL, CSize, R
  24. boolean FirstPass = True, Selected, DupMIB
  25.     
  26. --Set up modifiers------------------------------------------------------------
  27.  
  28. DefineModifier(0, '', ' ', False, 0.0)
  29. CSize = 1.0;        DefineModifier(1, 'SIZe', 'R', False, 1.0)
  30. SysVarI(1, IColor); DefineModifier(2, 'COLor', 'I', False, Real(IColor))
  31. SysVarI(2, IFont);  DefineModifier(3, 'FONt', 'I', False, Real(IFont))
  32. SysVarI(3, ILayer); DefineModifier(4, 'LAYer', 'I', False, Real(ILayer))
  33.  
  34. loop                                --loop to get modifiers
  35.     exit all when LastChar = Abort or LastChar = CR
  36.  
  37.     if not FirstPass or LastChar <> Colon then
  38.         AskModifiers(0)      --get modifier values from user
  39.         exit all when LastChar = Abort or LastChar = CR
  40.         GetModifier(1, Selected, CSize, SVal)
  41.         GetModifier(2, Selected, R, SVal); IColor = Integer(R)
  42.         GetModifier(3, Selected, R, SVal); IFont = Integer(R)
  43.         GetModifier(4, Selected, R, SVal); ILayer = Integer(R)
  44.     EndIf
  45.  
  46.     FirstPass = False              --FirstPass flag
  47.  
  48.     loop                           --loop to put in chamfer(s)
  49.         loop                       --loop to get at least 2 lines
  50.             TotEnts = 0
  51.             print 'pick lines near end to insert chamfer ',
  52.                  
  53.             --get entities to insert a chamfer to, (line ents only)
  54.                  
  55.             EntMask(0); EntMask(1)  --allow only lines to be picked
  56.             loop
  57.                 GetEnt(1, NEnts, MIBNums(TotEnts+1), IEnd(TotEnts+1))
  58.                 exit all when LastChar=Abort or (TotEnts=0 and LastChar=CR)
  59.                 exit 3 when LastChar = Colon 
  60.                 exit when NEnts = 0 or LastChar = Semi
  61.                 DupMib = False
  62.                 loop I = 1 to TotEnts
  63.                     if MIBNums(TotEnts+1) = MIBNums(I) then
  64.                         DupMIB = True; exit loop
  65.                     endif
  66.                 end loop
  67.                 if not DupMIB then
  68.                     TotEnts = TotEnts+1
  69.                     verify line EntID(MIBNums(TotEnts)) \
  70.                                 Ends(LinEnds(1,TotEnts), LinEnds(2,TotEnts))
  71.                 endif
  72.                 exit when TotEnts = 30 
  73.             EndLoop
  74.             exit when TotEnts > 1           --got all the entities we need
  75.             exit 2 when LastChar = Colon    --go back to modifier processor
  76.             WarnMsg('<at least 2 lines must be selected, pick some more>')
  77.         EndLoop
  78.  
  79.         --calculate new line end points and chamfer area end points
  80.  
  81.         loop I = 1 to TotEnts
  82.  
  83.             --calculate new end point, which end to modify is determined
  84.             --by which end of the line was digitize closest to
  85.  
  86.             if IEnd(I) = 1 then OtherEnd = 2; else OtherEnd = 1; EndIf
  87.             NewL = VLen(LinEnds(1,I), LinEnds(2,I))-CSize
  88.             NewEnd(I) = (VUnit(LinEnds(IEnd(I),I)-LinEnds(OtherEnd,I)) * \
  89.                          Coord(NewL, NewL, NewL)) + LinEnds(OtherEnd,I)
  90.             modify line EntID(MIBNums(I)) Rpnt(True) \       --update the line
  91.                         Ends(LinEnds(OtherEnd,I), NewEnd(I)) --in the database
  92.         EndLoop
  93.         
  94.         if TotEnts > 2 then
  95.             TotEnts = TotEnts+1
  96.             NewEnd(TotEnts) = NewEnd(1)
  97.         endif
  98.  
  99.         Insert String verts(TotEnts, NewEnd(1)) rpnt(True) \--put chamfer
  100.                       color(IColor) layer(ILayer) font(IFont) --in as a string
  101.         exit all when LastChar = CR     --all done
  102.         exit when LastChar = Colon      --get new modifiers
  103.     EndLoop      
  104. EndLoop
  105. end proc
  106.  
  107.