# Mattenliste mit Schneideskizze für Planeinfügung
# Wird in Plan abgelegt.
# 18.08.2011/LF 
# Anpassung für alle Eingabeeinheiten 21.01.2018/LF

save_fsm(); #Voreinstellung sichern

# Zuweisung Variablennamen
name(i30,"reihe") ;
name(i31,"spalte");
name(i32,"blatnr");
name(i33,"anzlis");
name(r30,"abstx");
name(r31,"absty");

name(i40,"penrah");
name(i41,"penpos");
name(i42,"penlb") ;
name(i43,"penbez");
name(r40,"txhvau");
name(r41,"txhpos");
name(r42,"txhlb") ;
name(r43,"txhbez");
name(r44,"mstb");


name(s30,"bauva");
name(s31,"bauvb");
name(s32,"bauta");
name(s33,"bautb");
name(s34,"plnr");
name(s35,"prjnr");
name(s36,"datu");
name(s37,"lisnr");
name(s38,"gezei");
name(s39,"koptxt");

name (i50, "color");

#***----------------------------------------***
# globale Voreinstellung

color = 7; # globale Farbeinstellung
i20 = 0; gst_weight(i20); # Linienstärke Texte
i21 = 0; gsl_weight(i21); # Linienstärke 
i22 = 0; gsl_type(i22);   # Linientyp
#***----------------------------------------***

# Zuweisung Farben und Texthöhen Matten
# penrah = 14;    # Farbe fuer den Rahmen               0=Nicht zeichnen
#txhvau = 0.0 ;  # Texthoehe fuer den Auszug darunter  0.0 = nicht
#penpos = color;
#txhpos = 17.5;  # Farbe+Texthoehe Positionsnummer in Matte
#penlb  = color;
#txhlb  = 10.0;  # Farbe+Texthoehe Laenge/Breite
#penbez = color;
#txhbez = 17.5;  # fuer Bezeichnung ueber der Matte

#  --------------------------------------------------------------
# Maske Maßstab festlegen

	dlg_init(): #Init new Dialog

	dlg_label(1,2,"Ausgabemaßstab?",30); #25= use 25 columns for text
#Listbox
	dlg_list_set(1,"1 :  -",1);                    #(nr,text,item)
	dlg_list_set(2,"1 : 25",1);
	dlg_list_set(3,"1 : 50",1);
	dlg_list_set(4,"1 : 20",1);
	dlg_list_set(5,"1 : 10",1);
	dlg_list_set(6,"1 :100",1);
	dlg_list_set(7,"1 :  5",1);
	dlg_listbox(1,3,"Auswahl     ",10,1);          #(x,y,text,width,item)
#Edit Field
	i92 = 50;
	dlg_editbox(1,4,"oder Eingabe",i92,10);    #use blanks for text width
	dlg_label(1,5,"Listenfarbe komplette Liste (min 1, max 253)",50); #25= use 25 columns for text
	#ColorPicker
	dlg_colorpick(1,6,"Farbe eingeben oder wählen",color);
	dlg_editbox(1,7,"Linienbreite ",i21,5);    #use blanks for text width
	dlg_editbox(1,8,"L-Breite Text",i20,5);    #use blanks for text width
	dlg_editbox(1,9,"Linientyp    ",i22,5);    #use blanks for text width
	dlg_label(1,10,"Geben Sie nach 'OK' den Einfügepunkt",40); #25= use 25 columns for text
	dlg_label(1,11,"an (linke untere Ecke)",40); #25= use 25 columns for text

	dlg_start("Maßstab wählen",i5); # 0= OK;  -1=Cancel;  > 0 =Button Number

	if( i5 < 0) then
      begin
	writeln("Dialog Canceld ");
      end;
	if((i92 > 0) and ( i5 >= 0)) then
    begin
	 dlg_list_get(s7,i1,1);
	  if (s7 = "1 :  -") then i93 = 0;
	  if (s7 = "1 : 25") then i93 = 25;
	  if (s7 = "1 : 50") then i93 = 50;
	  if (s7 = "1 : 20") then i93 = 20;
	  if (s7 = "1 : 10") then i93 = 10;
	  if (s7 = "1 :100") then i93 = 100;
	  if (s7 = "1 :  5") then i93 = 5;
	  if (i93 > 0) then i92 = i93;
	
	mstb = (i92 / 100 * wcoiuf);

#  --------------------------------------------------------------

   setlayer("T_LISTEN_");

# writeln (mstb);
#Einfügepunkt auf 0 setzen
	p1.x = 0;
	p1.y = 0;
	p1.z = 0;

# Abfrage Einfügepunkt

		# Einfügepunkt 1. Skizze links unten
		write("Einfuegepunkt Schneideskizze:");
		read(p1);

  p11 = p1; # Lage Einfügepunkt sichern

#******************************************************************************
# Matten in Listen einfügen

   gst_justify(0); # unten links
   gst_rotation(0); # horizontal

penrah = color;   # Farbe fuer den Rahmen 0=Nicht zeichnen
txhvau = 0.0 ; # Texthoehe fuer den Auszug darunter  0.0 = nicht
penpos = color;
txhpos = (17.5 / 50 * mstb); # Farbe+Texthoehe Positionsnummer in Matte
penlb  = color;
txhlb  = (10.0 / 50 * mstb); # Farbe+Texthoehe Laenge/Breite
penbez = color;
txhbez = (17.5 / 50 * mstb); # fuer Bezeichnung ueber der Matte

# Einfügen Schneideskizzen
#  r45 = mstb * 2; # Massstab für Mattendarstellung
#     r45 = 100 / mstb; # Massstab für Mattendarstellung
   gst_justify(0); # unten links Text für Mattendarstellungen
-----------------
#  mbwbiegevor(r45,penrah,penpos,penlb,penbez,txhvau,txhpos,txhlb,txhbez);
# mbwbiegevor(wcouif,penrah,penpos,penlb,penbez,txhvau,txhpos,txhlb,txhbez);
------------------
r45 = 100 / i92;
mbwbiegevor(r45,penrah,penpos,penlb,penbez,txhvau,txhpos,txhlb,txhbez);
# 2.0 ist der faktor zum verkleinern der matte da list 1:100 und Plan 1:50
   
   abstx= 3.4 * mstb; # Mattenabstand x
   absty= 7.1 * mstb; # Mattenabstand y
   p3 = p1 ;
   p3.x = p3.x + 1.2 * mstb ; # Lage erste Darstellung x
   p3.y = p3.y + 0.7 * mstb ; # Lage erste Darstellung y

   blatnr = 1;
   reihe  = 0;
   spalte = 0;

   write(mbwanzbieg);
   
   for i88 = 1 to mbwanzbieg do
     begin
     
      p2 = p3 ;
      p2.x = p2.x + reihe * abstx;
      p2.y = p2.y + spalte * absty;
      p95 = p2; # Obere Kante sichern für Rand
      p95.x = p95.x - reihe * abstx;
      
      i87 = 5 ; # Anzahl Darst. nebeneinander
      if(spalte = 0) then i87 = 3 ; # 3 Darst. in 1 Reihe
          reihe = reihe + 1;
      if( reihe = i87) then
         begin
          reihe = 0;
          spalte = spalte + 1;
         end 

      mbwplbiege(p2,i88);
      
     end
# -------------------------------------------------
# Gewichtsliste schreiben

  s3 = "Schneideskizzen";
  s4 = "Maßstab 1 : 100";
  s5 = "Anzahl";
  s6 = "Bezeichnung";
  s7 = "Gewicht";
  s8 = "kg";
  s9 = "Gesamt";
  
  gst_weight(i20); # Linienstärke Texte
  gsl_weight(i21); # Linienstärke 
  gsl_type(i22);   # Linientyp

   p20 = p1;
   p20.x = p20.x + 11.4 * mstb;
   p20.y = p20.y + 7.15 * mstb;
   p21 = p20; p21.x = p21.x + 6.0 * mstb;
       line(p20,p21); # oberer Rand
   gst_height(0.25 * mstb);
   gst_justify(0);    # unten links
   gst_rotation(0.0); # horizontal
   gst_color(color);
   p22 = p20; p22.x = p22.x + 0.45 * mstb; p22.y = p22.y - 0.45 * mstb;
       text(p22,s4);
   gst_justify(1);    # unten mitte
   p22 = p20; p22.x = p22.x + 0.875 * mstb; p22.y = p22.y - 1.08 * mstb;
       text(p22,s5);
   p22.x = p22.x + 2.06 * mstb;
       text(p22,s6);
   p22.x = p22.x + 2.20 * mstb; p22.y = p22.y + 0.20 * mstb;
       text(p22,s7);
   p22.y = p22.y - 0.30 * mstb;
       text(p22,s8);
   p22 = p20; p22.y = p22.y - 1.30 * mstb;
       line(p20,p22); # Kopf links
   p22.x = p22.x + 6.0 * mstb;
       line(p21,p22); # Kopf rechts
   p20.y = p20.y - 1.30 * mstb; p21.y = p21.y - 1.30 * mstb;
       line(p20,p21); #kopf unten
       
   abstx = 2.0 * mstb; #  Textabstand Gewichtslistex
   absty = 0.5 * mstb; # Textabstand Gewichtsliste y
   p2  = p1;
   p2.x = p2.x + 11.8 * mstb;
   p2.y = p2.y + 5.45 * mstb;

   gst_height(12.5 / 50 * mstb);
   gst_justify(2);    # unten links
   gst_rotation(0.0); # horizontal
   gst_color(color);

      p22 = p20; p23 = p21;

    for i88 = 1 to mbwanzmatt do
     begin

      p3=p2;
      p3.x = p3.x + 0.75 * mstb;
      mbwliste(i88,"GANZ","7",s1);
      text(p3,s1);
      p3.x = p3.x + 2.35 * mstb;
      mbwliste(i88,"GTYP","7",s1);
      text(p3,s1);
      p3.x = p3.x + 2.28 * mstb;
      mbwliste(i88,"GGWP","7.2",s1);
      text(p3,s1);
      p2.y = p2.y - 0.5 * mstb ;
      p22.y = p22.y - 0.5 * mstb; p23.y = p23.y - 0.5 * mstb;
      line (p22,p23); # Unterstrich
      p24 = p22; p25 = p23;
      p24.y = p24.y + 0.5 * mstb; p25.y = p25.y + 0.5 * mstb;
      p26 = p22; p28 = p22; p27 = p22; p29 = p22;
      p26.x = p26.x + 1.75 * mstb; p28.x = p28.x + 4.0 * mstb;
      p27.x = p27.x + 1.75 * mstb; p29.x = p29.x + 4.0 * mstb;
      p27.y = p27.y + 0.5 * mstb; p29.y = p29.y + 0.5 * mstb;
      line (p22,p24); # links
      line (p23,p25); # rechts
      line (p26,p27); # mitte links
      line (p28,p29); # mitte rechts
      
     end

# -------------------------------------------------
# Summen schreiben
   p2.x = p2.x + 0.75 * mstb;
   p2.y = p2.y - 0.1 * mstb;
   mbwliste(i88,"GSTUECK","7",s1);
   text(p2,s1);
   p2.x = p2.x + 2.35 * mstb;
   text(p2,s9);
   p2.x = p2.x + 2.28 * mstb;
   mbwliste(i88,"GGEW","7.2",s1);
   text(p2,s1);
   p22.y = p22.y - 0.7 * mstb; p23.y = p23.y - 0.7 * mstb;
   line (p22,p23); # Unterstrich
   p24 = p22; p25 = p23;
   p24.y = p24.y + 0.7 * mstb; p25.y = p25.y + 0.7 * mstb;
   p26 = p22; p28 = p22; p27 = p22; p29 = p22;
   p26.x = p26.x + 1.75 * mstb; p28.x = p28.x + 4.0 * mstb;
   p27.x = p27.x + 1.75 * mstb; p29.x = p29.x + 4.0 * mstb;
   p27.y = p27.y + 0.7 * mstb; p29.y = p29.y + 0.7 * mstb;
   line (p22,p24); # links
   line (p23,p25); # rechts
   line (p26,p27); # mitte links
   line (p28,p29); # mitte rechts
   
   end # fi listart = 1

end;
end;

# Rand zeichnen -----------------------------------

  p2 = p1;
  p95.y = p95.y + 7 * mstb; # obere Randlinie hochschieben
  p95.x = p95.x -1.2 * mstb;
  p90 = p2; p91 = p2;
  p91.x = p91.x + 18.2 * mstb;
  line(p90,p91); # unterer Rand
  p92 = p95; p93 = p95;
  p93.x = p93.x + 18.2 * mstb;
  p94 = p92; p94.x = p94.x + 5.5 * mstb;
  line(p92,p94); # oberer Rand links
  p94 = p93; p94.x = p94.x - 5.5 * mstb;
  line(p94,p93); # oberer Rand rechts
  line(p90,p92); # linker Rand
  line(p91,p93); # rechter Rand

   gst_height(0.5 * mstb);
   gst_justify(4);    # mitte mitte
   gst_rotation(0.0); # horizontal
   gst_color(color);
     
     p92.x = p92.x + 9.1 * mstb;
     text(p92,s3);

restore_fsm(); # Voreinstellung wiederherstellen

END.
