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

  1. Procedure DivideLine;
  2. {
  3. ⌐1996, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie
  5.  
  6. This procedure divides a line into a given number of equal segments and/or places loci at the division points.
  7. }
  8.  
  9. LABEL 10,99;
  10.  
  11. VAR
  12.     x,y,x0,y0,x1,y1,x2,y2,dx,dy:REAL;
  13.     i,nSegs,TVal,Type:INTEGER;
  14.     ObjectH:HANDLE;
  15.     Abort,Loci,Segments,Erase : BOOLEAN;
  16.  
  17. Procedure Dialog;
  18. {
  19. This procedure creates the dialog box.
  20. }
  21. VAR
  22.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  23.  
  24. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  25. VAR
  26.     scrx1,scry1,scrx2,scry2:INTEGER;
  27. BEGIN
  28.     GetScreen(scrx1,scry1,scrx2,scry2);
  29.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  30.     x2:=x1+Width; 
  31. END;
  32.  
  33. Procedure LocateButtons(DialogType,scnh,scnw : INTEGER);
  34. {
  35. This procedure locates the 'OK' and 'Cancel' buttons.
  36. }
  37. VAR
  38.     v1,v2,v3,v4 : INTEGER;
  39.     Mac : BOOLEAN;
  40.  
  41. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  42. VAR
  43.     Temp : INTEGER;
  44. BEGIN
  45.     Temp:=m1;
  46.     m1:=m3;
  47.     m3:=Temp;
  48.     Temp:=m2;
  49.     m2:=m4;
  50.     m4:=Temp;
  51. END;        {of Swap}
  52.  
  53. BEGIN
  54.     Mac:=FALSE;
  55.     GetVersion(v1,v2,v3,v4);
  56.     IF v4 = 1 THEN Mac:=TRUE;
  57.  
  58.     IF DialogType = 1 THEN
  59.     BEGIN
  60.         px1:=(scnw DIV 2) - 80;
  61.         px2:=(scnw DIV 2) - 10;
  62.         px3:=(scnw DIV 2) + 10;
  63.         px4:=(scnw DIV 2) + 80;
  64.         IF Mac THEN SWAP(px1,px2,px3,px4);
  65.  
  66.         py1:=scnh-40;
  67.         py2:=scnh-20;
  68.         py3:=py1;
  69.         py4:=py2;
  70.     END ELSE IF DialogType = 2 THEN
  71.     BEGIN
  72.         px1:=scnw - 180;
  73.         px2:=scnw - 110;
  74.         px3:=scnw - 90;
  75.         px4:=scnw - 20;
  76.         IF Mac THEN SWAP(px1,px2,px3,px4);
  77.  
  78.         py1:=scnh-40;
  79.         py2:=scnh-20;
  80.         py3:=py1;
  81.         py4:=py2;
  82.     END ELSE
  83.     BEGIN
  84.         px1:=scnw - 90;
  85.         px2:=scnw - 20;
  86.         px3:=px1;
  87.         px4:=px2;
  88.  
  89.         py1:=scnh -70;
  90.         py2:=scnh - 50;
  91.         py3:=scnh - 40;
  92.         py4:=scnh - 20;
  93.         IF Mac THEN SWAP(py1,py2,py3,py4);
  94.     END;
  95. END;        {of Locate Buttons}
  96.  
  97. Procedure MakeDialog;
  98. {
  99. This procedure defines the dialog box.
  100. }
  101.  
  102. CONST
  103.     y1=100;
  104.     scnw = 230;
  105.     scnh = 200;
  106.     DialogType = 1;
  107.  
  108. VAR
  109.     h : INTEGER;
  110.  
  111. BEGIN
  112.     AlignScr(scnw,x1,x2);
  113.     y2:=y1+scnh;
  114.     LocateButtons(DialogType,scnh,scnw );
  115.     
  116.     BeginDialog(1,1,x1,y1,x2,y2);
  117.         AddButton('OK',1,1,px1,py1,px2,py2);
  118.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  119.  
  120.         h:=-30;
  121.         AddField('Options -',5,1,20,40+h,185,55+h);
  122.         AddButton('Place loci',6,2,20,60+h,160,75+h);
  123.         AddButton('Break line into segments',7,2,20,80+h,205,95+h);
  124.         AddButton('Leave original line intact',8,2,20,100+h,205,115+h);
  125.  
  126.         AddField('Number of segments:',9,1,20,140+h,165,155+h);
  127.         AddField('2',10,2,170,140+h,210,155+h);
  128.  
  129.     EndDialog;
  130. END;
  131.  
  132. BEGIN
  133.     MakeDialog;
  134. END;
  135.  
  136. Procedure GetInfo;
  137. {
  138. This procedure displays the dialog box and retrieves the information.
  139. }
  140. VAR
  141.     Item : INTEGER;
  142.     Done : BOOLEAN;
  143. BEGIN
  144.     Done:=FALSE;
  145.     Abort:=FALSE;
  146.     Loci:=TRUE;
  147.     Segments:=TRUE;
  148.     Erase:=FALSE;    
  149.     GetDialog(1);
  150.     SetTitle('Divide Line');
  151.     SetItem(6,Loci);
  152.     SetItem(7,Segments);
  153.     SetItem(8,NOT Erase);
  154.     SelField(10);
  155.     REPEAT
  156.         DialogEvent(Item);
  157.         IF Item=1 THEN
  158.             Done:=TRUE;
  159.         IF Item=2 THEN
  160.         BEGIN
  161.             Done:=TRUE;
  162.             Abort:=TRUE;
  163.         END;
  164.  
  165.         IF Item = 6 THEN
  166.         BEGIN
  167.             Loci:=NOT Loci;
  168.             SetItem(Item,Loci);
  169.             IF (NOT Loci) AND (NOT Segments) AND (Erase) THEN
  170.             BEGIN
  171.                 SetItem(8,TRUE);
  172.                 Erase:=False;
  173.             END;
  174.         END;
  175.  
  176.         IF Item = 7 THEN
  177.         BEGIN
  178.             Segments:=NOT Segments;
  179.             SetItem(Item,Segments);
  180.             IF (NOT Segments) AND (NOT Loci) THEN
  181.             BEGIN
  182.                 SetItem(8,TRUE);
  183.                 Erase:=False;
  184.             END;
  185.         END;
  186.  
  187.         IF Item = 8 THEN
  188.         BEGIN
  189.             Erase:=NOT Erase;
  190.             SetItem(Item,NOT Erase);
  191.             IF (Erase) AND (NOT Loci) THEN
  192.             BEGIN
  193.                 SetItem(7,TRUE);
  194.                 Segments:=TRUE;
  195.             END;
  196.         END;
  197.  
  198.     UNTIL Done;
  199.     NSegs:=Str2Num(GetField(10));
  200.     ClrDialog;
  201. END;
  202.  
  203. {
  204. Main Program.
  205. }
  206. BEGIN
  207. {
  208. Check to see if a line is selected
  209. }
  210.     ObjectH:=FSActLayer;
  211.     IF ObjectH = NIL THEN
  212.     BEGIN
  213.         Sysbeep;
  214.         AlrtDialog('You must select the line first!');
  215.         GOTO 99;
  216.     END;
  217.     TVal:=GetType(ObjectH);
  218.     IF TVal <> 2 THEN
  219.     BEGIN
  220.         Sysbeep;
  221.         AlrtDialog('The object selected is not a line!');
  222.         GOTO 99;
  223.     END;
  224. {
  225. Display the dialog box
  226. }
  227.     Dialog;
  228.     SetCursor(ArrowC);
  229. {
  230. Get the information from the dialog box.
  231. }
  232.     GetInfo;
  233.     IF Abort THEN GOTO 99;
  234. {
  235. Get the end points of the line and determint the length of the segments.
  236. }
  237.     GetSegPt1(ObjectH, x1,y1);
  238.     GetSegPt2(ObjectH, x2,y2);
  239.     dx:=(x1-x2)/nSegs;
  240.     dy:=(y1-y2)/nSegs;
  241. {
  242. Delete the original line.
  243. }
  244.     IF Erase THEN
  245.         DelObject(ObjectH);
  246.     x:=x1;
  247.     y:=y1;
  248.     Absolute;
  249.     MoveTo(x,y);
  250.     FOR i:=1 to nSegs-1 DO
  251.     BEGIN
  252.         x:=x1-i*dx;
  253.         y:=y1-i*dy;
  254. {
  255. Draw the new line segments.
  256. }
  257.         IF Segments THEN
  258.             LineTo(x,y);
  259. {
  260. Place loci.
  261. }
  262.         IF Loci THEN
  263.             Locus(x,y);
  264.     END;
  265. {
  266. Draw the last line segment.
  267. }
  268.     IF Segments THEN
  269.     BEGIN
  270.         x:=x1-i*dx;
  271.         y:=y1-i*dy;
  272.         LineTo(x,y);
  273.     END;
  274. 99:END;
  275.  
  276. RUN(DivideLine);