#!/usr/bin/python3
# -*- coding: utf-8 -*
# B. Vandeportaele 2022

import os
import sys
import math

imgdir="img"
os.system("mkdir -p "+imgdir)
	    
filename_scad="rubikscube.scad"
filename_wrl="rubikscube.wrl"
image_width=1024;
image_height=1024;

printerpart=(0,4,5,6,7,8,9)
orientation=(  "", "FCW"      ,  "FCCW"  , "UCW"     ,  "UCCW"  ,  "MCW"    , "MCCW")
for i in range(7):
  filename_image=imgdir+"/"+"rubiks_"+str(i)+"_"+orientation[i]+".png"
  commandline="openscad -D printerpart="+str(printerpart[i])+" -o "+filename_image+" --autocenter --viewall  --imgsize="+str(image_width)+","+str(image_height)+" "+"\""+filename_scad+"\""
  print("execution de: "+commandline)
  os.system(commandline)
  commandline="scp -P 2253  \""+filename_image+"\"  bvdp@bvdp.inetdoc.net:/home/bvdp/files/staubli/stl/"	  
  print("execution de: "+commandline)
  os.system(commandline)
 

#pour le wrl du rubikscube:
#to generate the .wrl directly:
commandline="./colorscad/colorscad.sh  -i \""+filename_scad+"\" -o \""+filename_wrl+"\" -f -j 4  -- -D printerpart="+str(0)
print("execution de: "+commandline)
os.system(commandline)
#to view the generated .wrl file
commandline="view3dscene \""+filename_wrl+"\" &"
print("execution de: "+commandline)
os.system(commandline)
commandline="scp -P 2253  \""+filename_wrl+"\"   bvdp@bvdp.inetdoc.net:/home/bvdp/files/staubli/stl/"	  
print("execution de: "+commandline)
os.system(commandline)



#pour le wrl de la cellule simplifiée:
filename_scad="cellule_simplifiee.scad"
filename_wrl="cellule_simplifiee.wrl"
commandline="./colorscad/colorscad.sh  -i \""+filename_scad+"\" -o \""+filename_wrl+"\" -f -j 4  -- -D printerpart="+str(0)
print("execution de: "+commandline)
os.system(commandline)
#to view the generated .wrl file
commandline="view3dscene \""+filename_wrl+"\" &"
print("execution de: "+commandline)
os.system(commandline)
commandline="scp -P 2253  \""+filename_wrl+"\"   bvdp@bvdp.inetdoc.net:/home/bvdp/files/staubli/stl/"	  
print("execution de: "+commandline)
os.system(commandline)

