!****h* General_VKN/Ruler
! NAME
! Ruler: Generate a set of 6 ruler at user specified location.
! Rulers may be in set to either metric or imperial mode and can
! be rotated along with the views.
! [Ruler.MBS]
!
! DESCRIPTION
! This module takes the following steps to draw a ruler line
! (See Figure 1 below for layout)
! at the origin aligned in the x-direction on the coordinate
! system provided by the user:
! * Set up units for either Metric or Imperial
! Base units per drawing unit
! * Calculate bounding box Delta x, y, and z and select maximum
! length
! * Set Ruler height (Ht) based on maximum length
! * Setup coordinate systems & Total Length for each of six rulers
! * Outer loop selects each coordinate system in succession
! * Draw horizontal ruler lines (See Figure)
! Turn off lines that are too dense to plot
! * Start loop to draw vertical ruler line (See Figure) &
! draw vertical lines
! * Return to Global
!
! |html

! |html Variable Name figure
!
! |html 
! |html Figure 2 - Bounding Box Layout
!
! SOURCE
GLOBAL GEOMETRY MODULE Ruler(
VECTOR Ptr, ! Rear bounding box point (See Figure 2)
Ptf; ! Front bounding box point
FLOAT Htmin:=0; ! Minimum Ruler height in base units
STRING Units*8:="IMPERIAL", ! "METRIC" or "IMPERIAL"
DrawingUnit*4:="INCH" ! Base drawing unit "MM" or "INCH";
);
!***
! ~ (End of RoboDoc input)
!***********************************************************************
! Copyright 2006, John J. Hughes (Email: n4yvt@arrl.net)
!
! This source code file is part of the 'NGBproject' files which
! execute interactively under the 'VARKON' program, which is
! distributed under the terms of the GNU General Public License.
!
! The 'NGBproject' files are also distributed under the terms of
! the GNU GeneralPublic License. See the GNU General Public License n
! included ithe file name "COPYING.txt" in the Varkon ./app/NGB/doc
! directory for more details.
!-----------------------------------------------------------------------
VECTOR TmpPt;
INT N,sublnk,iublnk,hublnk,uublnk,m;
FLOAT Tmp1,i,j,k,l,SU,IU,HU,UU,TU,Ht,DU,LRuler(6),XD,YD,ZD,Lmax,TL;
CONSTANT FLOAT Mult=0.03;
BEGINMODULE
!***********************************************************************
! ~ * Set up units for either Metric or Imperial !-----------------------------------------------------------------------
IF DrawingUnit="MM" THEN
IF Units="METRIC" THEN
i:=1; ! Base drawing unit is 'mm'
j:=10; ! 'cm'
k:=100; ! 'dm'
l:=1000; ! 'M'
DU:=1;
ELSE ! If user specifies "imperial"
i:=1/4;
j:=1; !inch is drawing unit
k:=12; !inchs per foot
l:=36; !inches per yards
DU:=25.4;
ENDIF;
ELSE ! Drawing unit is "INCH"
IF Units="METRIC" THEN
i:=1;
j:=10;
k:=100;
l:=1000;
DU:=1/25.4;
ELSE ! If user specifies "imperial"
i:=1/4;
j:=1; !inch is base drawing unit
k:=12; !inchs per foot
l:=36; !inches per yards
DU:=1;
ENDIF;
ENDIF;
!***********************************************************************
! Base units per drawing unit !-----------------------------------------------------------------------
SU:=DU*i; ! Smallest unit on ruler, see Figure 1
IU:=DU*j; ! Intermediate unit on ruler
HU:=DU*k; ! Highest unit on ruler
UU:=DU*l; ! Ultra High unit
!***********************************************************************
! ~ * Calculate bounding box Delta x, y, and z and select maximum length !-----------------------------------------------------------------------
XD:=Ptf.x-Ptr.x;
YD:=Ptf.y-Ptr.y;
ZD:=Ptf.z-Ptr.z;
Lmax:=0;
IF XD > Lmax THEN Lmax:=XD; ENDIF;
IF YD > Lmax THEN Lmax:=YD; ENDIF;
IF ZD > Lmax THEN Lmax:=ZD; ENDIF;
!***********************************************************************
! ~ * Set Ruler height (Ht) based on maximum length !-----------------------------------------------------------------------
Ht:=Mult*Lmax;
IF Ht < Htmin THEN
Ht:=Htmin;
ENDIF;
!***********************************************************************
! ~ * Setup coordinate systems & Total Length for each of six rulers !-----------------------------------------------------------------------
csys_1p(#1,"Ruler-1",vec(Ptr.x,Ptf.y-Ht,Ptf.z),90,90,0:BLANK=1);
Lruler(1):=Ptr.y-(Ptf.y-Ht);
csys_1p(#2,"Ruler-2",vec(Ptr.x,Ptf.y-Ht,Ptf.z),0,0,0:BLANK=1);
Lruler(2):=Ptf.x-Ptr.x;
csys_1p(#3,"Ruler-3",vec(Ptr.x,Ptf.y-Ht,Ptf.z),90,0,0:BLANK=1);
Lruler(3):=Ptf.x-Ptr.x;
csys_1p(#4,"Ruler-4",vec(Ptf.x,Ptf.y-Ht,Ptr.z),0,-90,0:BLANK=1);
Lruler(4):=Ptf.z-Ptr.z;
csys_1p(#5,"Ruler-5",vec(Ptf.x,Ptf.y-Ht,Ptr.z),-90,0,-90:BLANK=1);
Lruler(5):=Ptf.z-Ptr.z;
csys_3p(#6,"Ruler-6",vec(Ptf.x,Ptf.y-Ht,Ptr.z),
vec(Ptf.x,Ptr.y,Ptr.z),vec(Ptf.x+Ht,Ptf.y-Ht,Ptr.z):BLANK=1);
Lruler(6):=Ptr.y-(Ptf.y-Ht);
!***********************************************************************
! ~ * Outer loop selects each coordinate system in succession !-----------------------------------------------------------------------
! ~ m:=6;
FOR m:=1 TO 6 DO
mode_local(refc(m));
TL:=Lruler(m);
!***********************************************************************
! ~ * Draw horizontal ruler lines (See Figure) !-----------------------------------------------------------------------
lin_free(#10,vec(0,0),vec(TL,0));
lin_free(#20,vec(0,Ht/8),vec(TL,Ht/8));
lin_free(#30,vec(0,Ht/4),vec(TL,Ht/4));
lin_free(#34,vec(0,Ht/2),vec(TL,Ht/2));
lin_free(#40,vec(0,Ht),vec(TL,Ht));
!***********************************************************************
! ~ Turn off lines that are too dense to plot !-----------------------------------------------------------------------
iublnk:=0;
sublnk:=0;
hublnk:=0;
uublnk:=0;
IF TL/HU > 300 THEN hublnk:=1; ENDIF;
IF TL/IU > 300 THEN iublnk:=1; ENDIF;
IF TL/SU > 300 THEN sublnk:=1; ENDIF;
IF TL/UU > 300 THEN uublnk:=1; ENDIF;
!*********************************************************************** ! ~ * Start loop to draw vertical ruler line (See Figure) &
! ~ draw vertical lines !-----------------------------------------------------------------------
FOR N:=0 to round(TL/SU) DO
IF frac(N*SU/UU) < 0.0001 THEN
lin_free(#50,vec(N*SU,0),vec(N*SU,Ht):BLANK=uublnk);
ELIF frac(N*SU/HU) < 0.0001 THEN
lin_free(#60,vec(N*SU,0),vec(N*SU,Ht/2):BLANK=hublnk);
ELIF frac(N*SU/IU) < 0.0001 THEN
lin_free(#70,vec(N*SU,0),vec(N*SU,Ht/4):BLANK=iublnk);
ELSE ! Assume smallest unit
lin_free(#80,vec(N*SU,0),vec(N*SU,Ht/8):BLANK=sublnk);
ENDIF;
ENDFOR;
lin_free(#90,vec(TL,0),vec(TL,Ht)); ! Draw last vertical line
ENDFOR;
!***********************************************************************
! ~ * Return to Global !-----------------------------------------------------------------------
mode_global();
ENDMODULE