home *** CD-ROM | disk | FTP | other *** search
- -- 11-Mar-88 NEHolt; Created - UPL 3.0 demo program
- --
- -- ------------------------------------ DUALDIMS.UPL -------------
- -- PURPOSE: Provide "dual" English/Metric dimensioning. Digitize
- -- "English" dimension text, program calculates metric equivalent
- -- and then inserts the metric dimension in parenthesis right below
- -- the existing English value.
- --
- -- This program: I N C H E S o r F T / I N t o M E T E R S
-
- PROC MAIN
-
- INTEGER Ngot,Iend,j,k,i,ierr,EntMib(1),ix,ipower,ModSet
- BOOLEAN ModYes
- STRING Txt_Str:42,JunkStr:42,subString:42
- REAL Rval,X,Nearest
-
- -- * * * start of executable code * * *
- BREAK_CHAR = 3 -- set up CTRL-C to abort (ascii 03 = ^C)
- -- Set up a single modifier table. Modifier will be NEAREST.
- DefineModifier(1,'Nearest','R',True,0.01) -- default will be 0.01
- print '(modifier) ',
- AskModifiers(0) -- 0 = use UPL defined modifiers
- GetModifier(1,ModYes,Nearest,JunkStr) -- retrieve NEAREST value
- -- if entered by user.
- EntMask(6) -- only allow an LDIM entity or
- EntMask(4) -- a TEXT entity to be digitized
-
- NextDim:
- Print ': ent LDIM ', -- prompt user to digitize the LDIM text
- GetEnt(1,Ngot,EntMib(1),Iend) -- get mib of digitized ent
- if Ngot <> 1 then goto DONE;endif -- quit if none digitized
- Print
- -- Get dimension text string. This text string could be a decimal
- -- number, a number with a ' or " mark, or a value with a dash.
- RSubrecTX(EntMib(1),1,ierr,Txt_Str) -- Text string in "TX" subrec
- -- C O N V E R T D I M T E X T T O R E A L N U M
- -- Possible forms: xxx.xx, x'-y", x'-y a/b"
- RVal=0.0
- -- First try looking for a decimal point.
- ix=Index(Txt_Str,1,'.')
- If ix<>0 then -- D E C I M A L V A L U E
- Rval=Real(Txt_Str)
- else
- -- Try looking for a ' mark for FEET.
- JunkStr=Txt_Str
- ix=Index(Txt_Str,1,"'")
- if ix<>0 then -- F E E T V A L U E
- Rval=12.0*Real(Extract(Txt_Str,1,ix-1))
- JunkStr=Extract(Txt_Str,ix+1,99) -- Strip off FEET
- if Extract(JunkStr,1,1)='-' then
- JunkStr=Extract(JunkStr,2,99) -- Strip off "dash"
- endif
- endif
- -- Try looking for an " mark for INCHES
- ix=Index(JunkStr,1,'"')
- If ix<>0 then -- I N C H V A L U E
- JunkStr=Extract(JunkStr,1,ix-1) -- Strip off " sign
- Rval=Rval+Real(JunkStr)
- endif
- endif
- -- convert to metric (inches to meters)
- Rval=Rval*0.0254
-
- -- R O U N D C O N V E R T E D M E T R I C V A L U E
- Here1:
- -- Round the converted metric value (in Rval) to the nearest value
- -- in NEAREST. Ex: if Nearest =0.025 then round RVal to the nearest
- -- 0.025 meter. To do this, figure out how many times NEAREST goes
- -- into RVal. Round to nearest whole number. Then multiply by the
- -- NEAREST value to end up with the rounded metric dimension value.
- x=Rval/Nearest; JunkStr=STRING(x)
- i=INDEX(JunkStr,1,'E') -- look for an 'E' in the converted string
-
- -- if engineering notation then convert to straight decimal num.
- if i>0 then
- ipower=Integer(Extract(JunkStr,i+2,99))
- j=Index(JunkStr,1,'.') -- locate existing decimal point
- -- get characters between decimal point and 'E'
- subString=Extract(JunkStr,j+1,i-j-1)
- if i-j-1<ipower then -- pad extra zeroes if necessary
- loop k=1 to ipower-i+j+1
- subString=subString+'0'
- end_loop
- endif
- -- lop off extra characters if necessary
- if i-j-1>ipower then subString=EXTRACT(subString,1,ipower);endif
- -- Assemble entire number and add trailing decimal point
- JunkStr=Extract(JunkStr,1,j-1)+subString+'.'
- endif
-
- x=Real(Extract(JunkStr,1,(Index(JunkStr,1,'.')-1)))
- x=Nearest*x
- if (Rval-x)>=Nearest/2.0 then x=x+Nearest;Endif
- Rval=x
- JunkStr=String(Rval) -- convert metric dimension to text string
- -- C L E A N U P T H E C O N V E R T E D T E X T
- -- Determine the correct number of decimal places
- i=Index(JunkStr,1,'.')
- j=JunkStr.LENGTH
- if i<j then JunkStr=Extract(JunkStr,1,j-1);endif
- -- get rid of decimal point if string now ends in decimal point
- if i=JunkStr.LENGTH then JunkStr=Extract(JunkStr,1,i-1);endif
- -- add leading zero if first character is decimal point
- if i=1 then JunkStr='0'+JunkStr;Endif
- JunkStr=RmvChr(JunkStr,' ') -- remove any blank spaces
- Txt_Str=Txt_Str+'#13'+'('+JunkStr+' M)' -- append to end of English
-
- -- Write new dimension "TX" subrecord back to the database
- MSubrecTX(EntMib(1),1,ierr,Txt_Str)
- RpntEnt(EntMib(1),1,ierr) -- repaint the dimension text
- goto NextDim -- loop back up to allow another digitize
- DONE:
- END PROC
-