#### CUBE
!if $mode=1

!if $user=Terminer or $nbsteps>10
    status=done
!endif

!if $user=Choix de l'action
!if $ract=
         error = noaction
!else
 !advance step
!endif
!endif

!if $user=Choix des points
 !advance step
!if $rpt1= or $rpt2=
 error=notenoughinfo
!exit
!endif
 cept1=$rpt1
 cept2=$rpt2
 subst=0
 linesubst=
 !if ($cept1 isitemof $auxpt) or ($cept2 isitemof $auxpt)
   !read relieaux
   !goto finsubst
 !endif
 !if ($cept1 isitemof $substpt) and ($cept2 isitemof $substpt)
   !read doublesubst
   !goto finsubst
 !endif
 !if $cept1 isitemof $substpt
   subst=1
!!debug $cept1
   trouve=0
     !for ii = 1 to 24
       !for ll=0 to 3
          l1=!eval $ll*6+1
          l2=!eval $l1+5
       ceprol=  !item $l1..$l2 of $(prol$ii)
     !if $(ceprol[6])=$cept2 and $(ceprol[4])=$cept1
!!debug $ceprol $cept1 $cept2
       ptsplan = !replace item $cept1 by $(ceprol[5]) in $ptsplan
       ptsplan = !sort item $ptsplan
       ptsubst=$cept1
       cept1=$(ceprol[5])
       color$cept1=red
       linesubst=linewidth 1\
         dline $(pt$ptsubst),$(pt$cept1),green\
         linewidth 3
       trouve=1
!!debug $cept1 $cept2 $linesubst
       !goto finsubst
     !endif
     !if $(ceprol[6])=$cept2 and $(ceprol[5])=$cept1
       ptsplan = !replace item $cept1 by $(ceprol[4]) in $ptsplan
       ptsplan = !sort item $ptsplan
       ptsubst=$cept1
       cept1=$(ceprol[4])
       color$cept1=red
       linesubst=linewidth 1\
         dline $(pt$ptsubst),$(pt$cept1),green\
         linewidth 3
       trouve=1
       !goto finsubst
     !endif
   !next
   !next
   !if $trouve=0
     lien=$(relie$cept1)
     n= !itemcnt $lien
     !for jj=1 to $n
         ind= !eval 2*$jj - 1
         ind2= !eval 2*$jj
         !if $(lien[$ind])=$cept2
           ptsplan = !replace item $cept1 by $(lien[$ind2]) in $ptsplan
           ptsplan = !sort item $ptsplan
           ptsubst=$cept1
           cept1=$(lien[$ind2])
           color$cept1=red
           linesubst=linewidth 1\
             dline $(pt$ptsubst),$(pt$cept1),green\
             linewidth 3
           trouve=1
           !goto finsubst
         !endif
         !if $(lien[$ind2])=$cept2
           ptsplan = !replace item $cept1 by $(lien[$ind]) in $ptsplan
           ptsplan = !sort item $ptsplan
           ptsubst=$cept1
           cept1=$(lien[$ind])
           color$cept1=red
           linesubst=linewidth 1\
             dline $(pt$ptsubst),$(pt$cept1),green\
             linewidth 3
           trouve=1
           !goto finsubst
         !endif
     !next
   !endif
 !else
   !if $cept2 isitemof $substpt
     subst=1
     trouve=0
     !for ii = 1 to 24
       !for ll=0 to 3
          l1=!eval $ll*6+1
          l2=!eval $l1+5
       ceprol=  !item $l1..$l2 of $(prol$ii)
       !if $(ceprol[6])=$cept1 and $(ceprol[4])=$cept2
         ptsplan = !replace item $cept2 by $(ceprol[5]) in $ptsplan
         ptsplan = !sort item $ptsplan
         ptsubst=$cept2
         cept2=$(ceprol[5])
         color$cept2=red
         linesubst=linewidth 1\
           dline $(pt$ptsubst),$(pt$cept2),green\
           linewidth 3
         trouve=1
         !goto finsubst
       !endif
       !if $(ceprol[6])=$cept1 and $(ceprol[5])=$cept2
         ptsplan = !replace item $cept2 by $(ceprol[4]) in $ptsplan
         ptsplan = !sort item $ptsplan
         ptsubst=$cept2
         cept2=$(ceprol[4])
         color$cept2=red
         linesubst=linewidth 1\
           dline $(pt$ptsubst),$(pt$cept2),green\
           linewidth 3
         trouve=1
         !goto finsubst
       !endif
     !next
     !next
     !if $trouve=0
       lien=$(relie$cept2)
       n= !itemcnt $lien
       !for jj=1 to $n
          ind= !eval 2*$jj - 1
          ind2= !eval 2*$jj
          !if $(lien[$ind])=$cept1
            ptsplan = !replace item $cept2 by $(lien[$ind2]) in $ptsplan
            ptsplan = !sort item $ptsplan
            ptsubst=$cept2
            cept2=$(lien[$ind2])
            color$cept2=red
            linesubst=linewidth 1\
              dline $(pt$ptsubst),$(pt$cept2),green\
              linewidth 3
            trouve=1
            !goto finsubst
          !endif
          !if $(lien[$ind2])=$cept1
            ptsplan = !replace item $cept2 by $(lien[$ind]) in $ptsplan
            ptsplan = !sort item $ptsplan
            ptsubst=$cept2
            cept2=$(lien[$ind])
            color$cept2=red
            linesubst=linewidth 1\
              dline $(pt$ptsubst),$(pt$cept2),green\
              linewidth 3
            trouve=1
            !goto finsubst
          !endif
       !next
     !endif
   !endif
 !endif
:finsubst
 pt1=$(pt$cept1)
 pt2=$(pt$cept2)
 !if $subst=1
       lstpt=$cept1,$cept2
       lstpt= !sort item $lstpt
       !if $(lstpt[1])-$(lstpt[2]) notitemof $segsplan
           segsplan = !append item $(lstpt[1])-$(lstpt[2]) to $segsplan
           ptsplan = !append item $cept1 to $ptsplan
           ptsplan = !append item $cept2 to $ptsplan
           color$cept1=red
           color$cept2=red
           bary_x= $bary_x+ $(pt1[1])
           bary_y= $bary_y+ $(pt1[2])
           bary_x= $bary_x+ $(pt2[1])
           bary_y= $bary_y+ $(pt2[2])
           ptsplan = !listuniq $ptsplan
           ptsplan= !sort item $ptsplan
!!debug cept1 -$cept1- :$pt1 ou bien $ptK4 cept2 $cept2: $pt2 ind $ind ind2 $ind2
       !else
         error = dejaseg
       !endif
 !else
!! si le nom du point est sur 2 caractre ne prendre que le premier pour dterminer sa face
   fcept1 = !text copy $cept1 mask 10
   fcept2 = !text copy $cept2 mask 10
   ptcoplan=!listintersect $(face$fcept1) and $(face$fcept2)
   flptcoplan=!itemcnt $ptcoplan
    !if $flptcoplan=0
      error=$error ptnoncoplan
      !advance errcnt
    !else
      error=
## si les points sont A,I tracer A,B
      lstdte= !listintersect $(dte$fcept1) and $(dte$fcept2)
      n= !itemcnt $lstdte
!!debug $(dte$(fcept1)) ; $(dte$(fcept2)); $n 
      !if $n>0
        ladte = $(dte$(lstdte[1]))
        pt1=$(pt$(ladte[1]))
        pt2=$(pt$(ladte[2]))
!!debug $(lstdte[1]) : $lstdte : $ladte
        !if $(ladte[3]) notitemof $segsplan
           lstpt= $(ladte[1]),$(ladte[2])
           segsplan = !append item $(ladte[3]) to $segsplan
           ptsplan = !append item $(ladte[1]) to $ptsplan
           ptsplan = !append item $(ladte[2]) to $ptsplan
           color$(ladte[1])=red
           color$(ladte[2])=red
           bary_x= $bary_x+ $(pts$(ladte[1])[1])
           bary_y= $bary_y+ $(pts$(ladte[1])[2])
           bary_x= $bary_x+ $(pts$(ladte[2])[1])
           bary_y= $bary_y+ $(pts$(ladte[2])[2])
           ptsplan = !listuniq $ptsplan
           ptsplan= !sort item $ptsplan
        !else
          error = dejaseg
        !endif
      !else
        lstpt=$cept1,$cept2
        lstpt= !sort item $lstpt
        !if $(lstpt[1])-$(lstpt[2]) notitemof $segsplan
           segsplan = !append item $(lstpt[1])-$(lstpt[2]) to $segsplan
        !else
          error = dejaseg
        !endif
      !endif
    !endif
   !endif
!if $error=
 !! choix entre segment pointill et segment plein
 fcept1=!text copy $(lstpt[1]) mask 10
 fcept2=!text copy $(lstpt[2]) mask 10
 faceseg= !listintersect $(face$fcept1) and $(face$fcept2)
 faceseg= !listintersect $faceseg and 2,3,6
 !if $faceseg=
   typeline=dline
 !else
   typeline=line
 !endif
 cadre = $cadre \
 $typeline $pt1,$pt2,yellow\
 $linesubst
!endif
!endif




!if $user=Choix de la parallle
!read parallele
!endif

!read section2

!if $user=Etape prcdente
!advance step
!advance errcnt
!endif


!endif
#### CUBE
