home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / tema / MINICAD / MC7DEMO / MINICAD.1 / CRE_DTS.MPC < prev    next >
Text File  |  1997-04-30  |  5KB  |  297 lines

  1. Procedure DatumTarget;
  2. {
  3. ⌐1997, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie
  5.  
  6. This procedure creates a Datum Target Symbol.
  7. }
  8.  
  9. LABEL 10,99;
  10.  
  11. CONST
  12. {The following constant determines the default symbol size for 10 pt. text}
  13.     SDiaC=0.4375;
  14. {The following four constants are used to determine the location of the text within in the symbol.}
  15.     TextOff1C=0.180;
  16.     TextOff2C=0.062;
  17.     TextOff3C=0.011;
  18.     TextOff4C=0.072;
  19.  
  20. VAR
  21.     x0,y0,xs,ys,xt,yt,h : REAL;
  22.     TextOff1,TextOff2,TextOff3,TextOff4,SDia,LScale : REAL;
  23.  
  24.     TxtSize : INTEGER;
  25.  
  26.     DatumID,TASize,TargetNo : STRING;
  27.     DiaChar : CHAR;
  28.  
  29.     TDia,Abort : BOOLEAN;
  30.     LayerH : HANDLE;
  31.  
  32.     UPI : REAL;
  33.     Fmt : INTEGER;
  34.     UM,UM2 : STRING;
  35.     UName,DA : LONGINT;
  36.  
  37. Procedure DatumTargetDialog;
  38. {
  39. This procedure defines the dialog box.
  40. }
  41. VAR
  42.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  43.  
  44. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  45. VAR
  46.     scrx1,scry1,scrx2,scry2:INTEGER;
  47. BEGIN
  48.     GetScreen(scrx1,scry1,scrx2,scry2);
  49.     x1:=((scrx1+scrx2) div 2) - (Width div 2);
  50.     x2:=x1+Width; 
  51. END;
  52.  
  53. Procedure LocateButtons2(scnh,scnw : INTEGER);
  54. {
  55. This procedure locates the 'OK' and 'Cancel' buttons at the lower left hand corner of the dialog box.
  56. }
  57. VAR
  58.     v1,v2,v3,v4 : INTEGER;
  59.  
  60. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  61. VAR
  62.     Temp : INTEGER;
  63. BEGIN
  64.     Temp:=m1;
  65.     m1:=m3;
  66.     m3:=Temp;
  67.     Temp:=m2;
  68.     m2:=m4;
  69.     m4:=Temp;
  70. END;        {of Swap}
  71.  
  72. BEGIN
  73.     px1:=scnw - 180;
  74.     px2:=scnw - 110;
  75.     px3:=scnw - 90;
  76.     px4:=scnw - 20;
  77.  
  78.     py1:=scnh-40;
  79.     py2:=scnh-20;
  80.     py3:=py1;
  81.     py4:=py2;
  82.  
  83.     GetVersion(v1,v2,v3,v4);
  84.     IF v4 = 1 THEN Swap(px1,px2,px3,px4);
  85.  
  86. END;        {of Locate Buttons1}
  87.  
  88. Procedure MakeDatumTargetDialog;
  89. LABEL 99;
  90.  
  91. CONST
  92.     y1=100;
  93.     scnh=160;
  94.     scnw=300; 
  95.  
  96. VAR
  97.     h : INTEGER;
  98.  
  99. BEGIN
  100.     AlignScr(scnw,x1,x2);
  101.     y2:=y1+scnh;
  102.     LocateButtons2(scnh,scnw);
  103.  
  104.     h:=30;
  105.     BeginDialog(1,1,x1,y1,x2,y2);
  106.         AddButton('OK',1,1,px1,py1,px2,py2);
  107.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  108.  
  109.         AddField('Target Area Size:',5,1,20,44-h,130,60-h);
  110.         AddField('6',6,2,135,45-h,190,60-h);
  111.  
  112.         AddButton('Diameter',7,3,200,45-h,275,60-h);
  113.  
  114.         AddField('Datum ID Letter:',8,1,20,74-h,130,90-h);
  115.         AddField('A',9,2,135,75-h,190,90-h);
  116.  
  117.         AddField('Target Number:',10,1,20,104-h,130,120-h);
  118.         AddField('8',11,2,135,105-h,190,120-h);
  119.  
  120.         EndDialog;
  121. END;
  122.  
  123. BEGIN
  124.     MakeDatumTargetDialog;
  125. END;
  126.  
  127. Procedure GetInfo;
  128. {
  129. This procedure displays the dialog box and retrieves the information.
  130. }
  131. VAR
  132.     Done:Boolean;
  133.     Item:Integer;
  134. BEGIN
  135.     Done:=FALSE;
  136.     Abort:=FALSE;
  137.     TDia:=FALSE;
  138.     TASize:=' ';
  139.     DatumID:=' ';
  140.     TargetNo:=' ';
  141.     GetDialog(1);
  142.     SetTitle('Datum Target Symbol');
  143.     SelField(6);
  144.     REPEAT
  145.         DialogEvent(Item);
  146.         IF Item=1 THEN
  147.             Done:=TRUE;
  148.  
  149.         IF Item=2 THEN
  150.         BEGIN
  151.             Done:=TRUE;
  152.             Abort:=TRUE;
  153.         END;
  154.  
  155.         IF Item=7 THEN
  156.         BEGIN
  157.             TDia:=NOT TDia;
  158.             SetItem(7,TDia);
  159.         END; 
  160.  
  161.     UNTIL Done;
  162.     TASize:=GetField(6);
  163.     DatumID:=GetField(9);
  164.     TargetNo:=GetField(11);
  165.     ClrDialog;
  166. END;
  167.  
  168. Function GetActTextSize : INTEGER;
  169. {
  170. This function returns the active  text size.
  171. }
  172. VAR
  173.     a : INTEGER;
  174.     TextH : HANDLE;
  175.  
  176. BEGIN
  177.     DSelectAll;
  178.     TextOrigin(0,0);
  179.     BeginText;
  180.         ' '
  181.     EndText;
  182.     TextH:=FSActLayer;
  183.     GetActTextSize:=GetSize(TextH);
  184.     DelObject(TextH);
  185. END;
  186.  
  187. {
  188. Main program.
  189. }
  190. BEGIN
  191. {
  192. Display dialog box and get info.
  193. }
  194.  
  195.     DatumTargetDialog;
  196.     SetCursor(ArrowC);
  197.     GetInfo;
  198.     IF Abort THEN GOTO 99;
  199.     TextJust(2);
  200.     TextSpace(2);
  201.  
  202. {
  203. Get text size.
  204. }
  205.  
  206.     TxtSize:=GetActTextSize;
  207.     DiaChar:=Chr(175);
  208.  
  209. {
  210. Get units per inch and layer scale.
  211. }
  212.  
  213.     LayerH:=ActLayer;
  214.     LScale:=GetLScale(LayerH);
  215.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  216.  
  217. {
  218. Adjust constants for layer scale, units per inch, and text size.
  219. }
  220.  
  221.     h:=TxtSize/10;
  222.     LScale:=h*LScale;
  223.     SDia:=SDiaC*UPI*LScale;
  224.     TextOff1:=TextOff1C*UPI*LScale;
  225.     TextOff3:=TextOff3C*UPI*LScale;
  226.     TextOff4:=TextOff4C*UPI*LScale;
  227.     TextOff2:=TextOff2C*UPI*LScale;
  228.  
  229. {
  230. Get datum target symbol location and draw circle.
  231. }
  232.  
  233.     DSelectAll;
  234.     GetPt(x0,y0);
  235.     FillPat(1);
  236.     BeginGroup;
  237.     Absolute;
  238.     MoveTo(x0,y0);
  239.     Relative;
  240.     Arc(-SDia/2,SDia/2,SDia/2,-SDia/2,0,360);
  241.     Move(-SDia/2,0);
  242.     Line(SDia,0);
  243.     Absolute;
  244.     FillPat(0);
  245.  
  246. {
  247. Add diameter character, if needed and determine location of target area size.
  248. }
  249.  
  250.     IF TDia THEN
  251.         TASize:=Concat(DiaChar,TASize);
  252.     xt:=x0;
  253.     yt:=y0+TextOff1;
  254.  
  255. {
  256. Enter target area size.
  257. }
  258.  
  259.     IF TASize <> '' THEN
  260.     BEGIN
  261.         TextOrigin(xt,yt);
  262.         BeginText;
  263.             TASize
  264.         EndText;
  265.     END;
  266.  
  267. {
  268. Determine location of datum ID letter and enter into symbol.
  269. }
  270.  
  271.       yt:=y0-TextOff3;
  272.     IF DatumID <> '' THEN
  273.     BEGIN
  274.         xt:=x0-TextOff4;
  275.         TextOrigin(xt,yt);
  276.         BeginText;
  277.              DatumID
  278.         EndText;
  279.     END;
  280.  
  281. {
  282. Determine location of target number and enter into symbol.
  283. }
  284.  
  285.     IF TargetNo <> '' THEN
  286.     BEGIN
  287.         xt:=x0+TextOff2;
  288.         TextOrigin(xt,yt);
  289.         BeginText;
  290.              TargetNo
  291.         EndText;
  292.     END;
  293.     EndGroup;
  294.     PopAttrs;
  295. 99:END;
  296.  
  297. RUN(DatumTarget);