- HOT

var local &DIM &STYLE &TEXT &TOL_POS &TOL_NEG &NDEC &FORMAT &NDEC_I &NDEC_M

if typ(#0) = '-'  ;* hotkey 
  try
    &DIM = vdim(#C)
    &STYLE = style(&DIM)
  rec
    bell
    ret
  yrt
  if &STYLE = 1 | &STYLE = 2 | &STYLE = 3
    if &STYLE = 1 & ysta(&DIM) = yfin(&DIM)
      &STYLE = 3
    else
      &STYLE = 1+mod(&STYLE 3)
    fi
  else if &STYLE = 22 | &STYLE = 23
    &STYLE = 45-&STYLE
  else if &STYLE = 11 | &STYLE = 12
    &STYLE = 23-&STYLE
  else if &STYLE = 13 | &STYLE = 14
    &STYLE = 27-&STYLE
  else
    ret
  fi
  cha &DIM style &STYLE
  
  if pdim
    pdim last
    pdim text form('cha last style %.0f' &STYLE)
  fi
  ret
fi

<getstyle>
menu disp 410
pro
help context 22502	;* Edit Dimensions
if pdim
  menu jump <410>
else
  hotkey
  if escape
    ret
  else if #E <> 0
    menu jump <410>
  fi
fi
jump <getstyle>

<410.0>
ret

<410.1>
<410.2>
<410.3>
&STYLE = #J
menu high #J
jump <newstyle>

<410.4>
<410.5>
&STYLE = #J+7 ;* 11 = small, 12 = large
menu high #J
jump <newstyle>

<410.6>
<410.7>
<410.8>
&STYLE = #J+44 ;* 50 = regular, 51 = tolerance text, 52 = limits text
menu high #J
if &STYLE > 50
  pro #5042 val &TOL_POS ;* "Give the + tolerance"
  if escape jump <getstyle>; fi
  pro #5043 val &TOL_NEG show #B ;* "Give the - tolerance"
  if escape jump <getstyle>; fi
  if round(&TOL_POS .1) = &TOL_POS
    N = 1
  else if round(&TOL_POS .01) = &TOL_POS
    N = 2
  else if round(&TOL_POS .001) = &TOL_POS
    N = 3
  else if round(&TOL_POS .0001) = &TOL_POS
    N = 4
  else if round(&TOL_POS .00001) = &TOL_POS
    N = 5
  else
    N = 6
  fi
  if round(&TOL_NEG .1) = &TOL_NEG
    &NDEC = 1
  else if round(&TOL_NEG .01) = &TOL_NEG
    &NDEC = 2
  else if round(&TOL_NEG .001) = &TOL_NEG
    &NDEC = 3
  else if round(&TOL_NEG .0001) = &TOL_NEG
    &NDEC = 4
  else if round(&TOL_NEG .00001) = &TOL_NEG
    &NDEC = 5
  else
    &NDEC = 6
  fi
  if N > &NDEC
    &NDEC = N
  fi
  &FORMAT = form('%%.%.0ff' &NDEC)
fi
jump <newstyle>

<410.9> * inch + metric
pro "Number of decimals for metric [ 1 ] :" val &NDEC_M def 1
if escape jump <getstyle>; fi
pro "Number of decimals for inches [ 3 ] :" val &NDEC_I def 3
if escape jump <getstyle>; fi
pro #911 ;* "Do you want to drop trailing zeros?"
mac YESNO
if #E = 900
  jump <getstyle>
else if #E = 0
  &NDEC_M = -abs(round(&NDEC_M 1))
  &NDEC_I = -abs(round(&NDEC_I 1))
else
  &NDEC_M =  abs(round(&NDEC_M 1))
  &NDEC_I =  abs(round(&NDEC_I 1))
fi
&STYLE = 9
jump <newstyle>

<newstyle>
high 1 select
if len(last) > 0
  sup last if typ(*) <> 'DIM' ;* deselect any dims
  high 1 select
  if &STYLE = 11 | &STYLE = 12
    sup last if style(*) < 11 | style(*) > 14
  else if &STYLE = 1 | &STYLE = 2
    sup last if style(*) < 1 | style(*) > 3 & style(*) < 22 | style(*) > 23
  else if &STYLE = 3
    sup last if style(*) < 1 | style(*) > 3
  else if &STYLE = 9
    sup last if style(*) < 1 | style(*) = 5
  else
    sup last if style(*) < 1
  fi
  high 1 select
fi
if len(last) = 0
  pro #1665 ;* "Select the dimensions to change the style of"
  if &STYLE = 11 | &STYLE = 12
    mac SELECT only "type(*) = 'DIM' & style(*) >= 11 & style(*) <= 14"
  else if &STYLE = 1 | &STYLE = 2
    mac SELECT only "type(*) = 'DIM' & style(*) >= 1 & style(*) <= 3 | type(*) = 'DIM' & style(*) >= 22 & style(*) <= 23"
  else if &STYLE = 3
    mac SELECT only "type(*) = 'DIM' & style(*) >= 1 & style(*) <= 3"
  else if &STYLE = 9
    mac SELECT only "type(*) = 'DIM' & style(*) >= 1 & style(*) <> 5"
  else
    mac SELECT only "type(*) = 'DIM' & style(*) >= 1"
  fi
  if #E <> 0
    jump <getstyle>
  fi
fi

temp copy
undo copy TEMP
N = 1
if &STYLE = 1
  if style(temp(N)) >= 22  cha temp(N) style 23;  else cha temp(N) style 1; fi;  N = N+1; if N <= len(temp) jump; fi
else if &STYLE = 2
  if style(temp(N)) >= 22  cha temp(N) style 22;  else cha temp(N) style 2; fi;  N = N+1; if N <= len(temp) jump; fi
else if &STYLE = 3
  cha TEMP style 3
else if &STYLE = 11
  if style(temp(N)) >= 13  cha temp(N) style 13;  else cha temp(N) style 11; fi;  N = N+1; if N <= len(temp) jump; fi
else if &STYLE = 12
  if style(temp(N)) >= 13  cha temp(N) style 14;  else cha temp(N) style 12; fi;  N = N+1; if N <= len(temp) jump; fi
else
  * Tolerances
  <nexttol>
  * If inappropriate to apply to this dimension type, go to next: Don't do these transformation to notes
  if style(temp(N)) = 25
    N = N+1
    if N <= len(temp)
      jump <nexttol>
    else
      jump <out>
    fi
  fi
  if &STYLE = 9  ;* inch + metric
    par(40) = &NDEC_M ; if par(40) = 0  par(40) = -99; fi
    &TEXT = ffor(value(temp(N))/&DIM_SCALE*25.4/#U 0 0 1)
    par(40) = &NDEC_I ; if par(40) = 0  par(40) = -99; fi
    &TEXT = &TEXT,'\\',ffor(value(temp(N))/&DIM_SCALE/#U 0 0 1)
  else if &STYLE = 52 ;* limits
    &TEXT = '{,',form(&FORMAT value(temp(N))/&DIM_SCALE+&TOL_POS),',',form(&FORMAT value(temp(N))/&DIM_SCALE-&TOL_NEG),'}'
  else
    if &STYLE = 50 ;* regular
      if style(temp(N)) = 5
        par(40) = par(82)
        &TEXT = ffor(value(temp(N))/&DIM_SCALE 60 -1 2)
      else
        par(40) = par(81)
        &TEXT = ffor(value(temp(N))/&DIM_SCALE 64 -1 3)
      fi
    else ;* tolerance
      &TEXT = form(&FORMAT value(temp(N))/&DIM_SCALE)
    fi
    try
      if style(temp(N)) = 5
        &TEXT = &_TEXT_DEG_PRE,&TEXT,&_TEXT_DEG_SUF
      else if style(temp(N)) = 11 | style(temp(N)) = 12
        &TEXT = &_TEXT_RAD_PRE,&TEXT,&_TEXT_RAD_SUF
      else if style(temp(N)) = 13 | style(temp(N)) = 14
        &TEXT = &_TEXT_DIAM_PRE,&TEXT,&_TEXT_DIAM_SUF
      fi
    yrt
    if &STYLE = 51 ;* tolerance
      &TEXT = '{',&TEXT,',+',form(&FORMAT &TOL_POS),',-',form(&FORMAT &TOL_NEG),'}'
    fi
  fi
  cha temp(N) string &TEXT
  N = N+1
  if N <= len(temp)
    jump <nexttol>
  fi
  <out>
  par(40) = par(81)
fi
undo new TEMP
high clear
jump <getstyle>
