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

  1. Procedure DatumFeature;
  2. {
  3. (c)1997, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie
  5.  
  6. This procedure creates a Datum Feature Symbol.
  7. }
  8.  
  9. LABEL 10,20,25,90,95,99;
  10.  
  11. CONST
  12. {The following constants determine the size of the datum feature symbol and text location for text size of 10 pt.}
  13.     BoxWdthC = 0.25;
  14.     BoxHgtC = 0.25;
  15.  
  16. {The following constant determines the height of of the datum feature marker for text size of 10 pt.}
  17.     htC=0.125;
  18.               
  19. VAR
  20.     a,b,h,ht,r1,Theta,x0,y0,x1,y1,x2,y2,xt : REAL;
  21.     BoxWdth,BoxHgt,LScale : REAL;
  22.     xb1,xb2,yb1,yb2 : REAL;
  23.  
  24.     TxtSize : INTEGER;
  25.     cR,cG,cB : LONGINT;
  26.     DatumRef : STRING;
  27.     Abort,Leader : BOOLEAN;
  28.     LayerH,TextH,GroupH : HANDLE;
  29.  
  30.     UPI : REAL;
  31.     Fmt : INTEGER;
  32.     UM,UM2 : STRING;
  33.     UName,DA : LONGINT;
  34.  
  35. Procedure DatumDialog;
  36. {
  37. This procedure creates the dialog box.
  38. }
  39. VAR
  40.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  41.  
  42. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  43. VAR
  44.     scrx1,scry1,scrx2,scry2:INTEGER;
  45. BEGIN
  46.     GetScreen(scrx1,scry1,scrx2,scry2);
  47.     x1:=((scrx1+scrx2) div 2 ) - (Width div 2);
  48.     x2:=x1+Width; 
  49. END;
  50.  
  51. Procedure LocateButtons2(scnh,scnw : INTEGER);
  52. {
  53. This procedure locates the 'OK' and 'Cancel' buttons at the lower left hand corner of the dialog box.
  54. }
  55. VAR
  56.     v1,v2,v3,v4 : INTEGER;
  57.  
  58. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  59. VAR
  60.     Temp : INTEGER;
  61. BEGIN
  62.     Temp:=m1;
  63.     m1:=m3;
  64.     m3:=Temp;
  65.     Temp:=m2;
  66.     m2:=m4;
  67.     m4:=Temp;
  68. END;        {of Swap}
  69.  
  70. BEGIN
  71.     px1:=scnw - 180;
  72.     px2:=scnw - 110;
  73.     px3:=scnw - 90;
  74.     px4:=scnw - 20;
  75.  
  76.     py1:=scnh-40;
  77.     py2:=scnh-20;
  78.     py3:=py1;
  79.     py4:=py2;
  80.  
  81.     GetVersion(v1,v2,v3,v4);
  82.     IF v4 = 1 THEN Swap(px1,px2,px3,px4);
  83.  
  84. END;        {of Locate Buttons1}
  85.  
  86. Procedure MakeDialog;
  87. CONST
  88.     y1=100;
  89.     scnh=125;
  90.     scnw=300;
  91.  
  92. VAR
  93.     h : INTEGER;
  94.  
  95. BEGIN
  96.     AlignScr(scnw,x1,x2);
  97.     y2:=y1+scnh;
  98.     LocateButtons2(scnh,scnw);
  99.  
  100.     BeginDialog(1,1,x1,y1,x2,y2);
  101.         AddButton('OK',1,1,px1,py1,px2,py2);
  102.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  103.  
  104.         h:=30;
  105.         AddField('Datum ID Letter:',5,1,20,44-h,140,60-h);
  106.         AddField('',6,2,145,45-h,205,60-h);
  107.  
  108.         AddButton('Draw leader line',7,2,20,75-h,170,90-h);
  109.     EndDialog;
  110. END;
  111.  
  112. BEGIN
  113.     MakeDialog;
  114. END;
  115.  
  116. Procedure GetInfo;
  117. {
  118. This procedure displays the dialog box and retrieves the information.
  119. }
  120. VAR
  121.     Done:Boolean;
  122.     Item:Integer;
  123.  
  124. BEGIN
  125.     Done:=FALSE;
  126.     Abort:=FALSE;
  127.     Leader:=TRUE;
  128.     GetDialog(1);
  129.     SetTitle('Datum Feature Symbol');
  130.     SelField(6);
  131.     SetItem(7, Leader);
  132.     REPEAT
  133.         DialogEvent(Item);
  134.         IF Item=1 THEN
  135.             Done:=TRUE;
  136.  
  137.         IF Item=2 THEN
  138.         BEGIN
  139.             Done:=TRUE;
  140.             Abort:=TRUE;
  141.         END;
  142.  
  143.         IF Item = 7 THEN
  144.         BEGIN
  145.             Leader:=NOT Leader;
  146.             SetItem(7, Leader);
  147.         END;
  148.     UNTIL Done;
  149.     DatumRef:=GetField(6);
  150.     ClrDialog;
  151. END;
  152.  
  153. Function GetActTextSize : INTEGER;
  154. {
  155. This function returns the active  text size.
  156. }
  157. VAR
  158.     a : INTEGER;
  159.     TextH : HANDLE;
  160.  
  161. BEGIN
  162.     DSelectAll;
  163.     TextOrigin(0,0);
  164.     BeginText;
  165.         ' '
  166.     EndText;
  167.     TextH:=FSActLayer;
  168.     GetActTextSize:=GetSize(TextH);
  169.     DelObject(TextH);
  170. END;
  171.  
  172. {
  173. Main program.
  174. }
  175. BEGIN
  176.     DSelectAll;
  177.     TextSpace(2);
  178.     TextJust(2);
  179.  
  180. {
  181. Display the dialog box and get the information.
  182. }
  183.  
  184.     DatumDialog;
  185.     SetCursor(ArrowC);
  186.     10:GetInfo;
  187.     IF Abort THEN GOTO 99;
  188.  
  189. {
  190. Get text size.
  191. }
  192.  
  193.     TxtSize:=GetActTextSize;
  194.  
  195. {
  196. Get layer scale and units per inch.
  197. }
  198.  
  199.     LayerH:=ActLayer;
  200.     LScale:=GetLScale(LayerH);
  201.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  202.  
  203. {
  204. Adjust the constants for layer scale, units per inch, and text size.
  205. }
  206.  
  207.     h:=TxtSize/10;
  208.     LScale:=h*LScale;
  209.     BoxWdth:=BoxWdthC*UPI*LScale;
  210.     BoxHgt:=BoxHgtC*UPI*LScale;
  211.     ht:=htC*UPI*LScale;
  212.  
  213. {
  214. Determine location of text.
  215. }
  216.  
  217.     Absolute;
  218.     DSelectAll;
  219.     xt:=BoxWdth/2;
  220.  
  221. {
  222. Get symbol location.
  223. }
  224.  
  225.     GetPt(x0,y0);
  226.  
  227. {
  228. Draw symbol and enter text.
  229. }
  230.  
  231.     FillPat(1);
  232.     Absolute;
  233.     MoveTo(x0-BoxWdth/2,y0+BoxHgt/2);
  234.     Relative;
  235.     Rect(0,0,BoxWdth,-BoxHgt);
  236.  
  237.     FillPat(0);
  238.     IF DatumRef = '' THEN GOTO 25;
  239.     Absolute;
  240.     TextOrigin(x0,y0);
  241.     BeginText;
  242.         DatumRef
  243.     EndText;
  244.     TextH:=LSActLayer;
  245.     GetBBox(TextH,xb1,yb1,xb2,yb2);
  246.     HMove(TextH,0,(yb1-yb2)/2);
  247.  
  248.     25:Group;
  249.     GroupH:=LSactLayer;
  250.     IF NOT Leader THEN GOTO 95;
  251.  
  252.     ReDraw;
  253.     DSelectAll;
  254.     Absolute;
  255.     MoveTo(x0,y0);
  256.     GetPtL(x0,y0,x1,y1);
  257.     LineTo(x1,y1);
  258.     DoMenuText('Send to Back');
  259.     Redraw;
  260.  
  261.     GetPtL(x1,y1,x2,y2);
  262.     IF (x1 = x2) AND (y1 = y2) THEN GOTO 20;
  263.     LineTo(x2,y2);
  264.     x0:=x1; y0:=y1;
  265.     x1:=x2; y1:=y2;
  266.  
  267.     20:r1:=Distance(x0,y0,x1,y1);
  268.     Theta:=Rad2Deg(ArcCos((x1-x0)/r1));
  269.     IF y1 < y0 THEN
  270.         Theta:=360 - Theta;
  271.     a:=ht/Cos(Pi/6);
  272.     b:=2*ht*Tan(Pi/6);
  273.     MoveTo(x1,y1);
  274.     Relative;
  275.     AngleVar;
  276.     Move(-b/2,#(Theta-90));
  277.     ClosePoly;
  278.     FillPat(2);
  279.     FPenFore(cR,cG,cB);
  280.     FillFore(cR,cG,cB);
  281.     BeginPoly;
  282.         LineTo(0,0);
  283.         LineTo(b,#(Theta-90));
  284.         LineTo(-a,#(Theta-30));
  285.     EndPoly;
  286.     SetSelect(GroupH);
  287.     90:Group;
  288.     95:PopAttrs;
  289. 99:END;
  290.  
  291. RUN(DatumFeature);
  292.