#####################################
### DM2_w22  #  AGruber@tugraz.at ###
### hu_04_startUP # infra_4_tetra ###
#####################################

##############################
import rhinoscriptsyntax as rs      ###
import random, time, sys            ###
sys.path.append("P:/")              ### add LW P:/ to rhino's default search path AND
sys.path.append("P:/WWW/diag/")     ### add YOUR LW P:/WWW/user/ to rhino's default search path ...
import DM2_lib as dm                ### ... thus DM2_lib.py can be found !
##############################


rs.UnitSystem(4)
rs.ShowGrid(None, 1)
rs.ShowGridAxes(None, 1)
rs.ViewDisplayMode(view=None, mode="Ghosted")

dm.eA()                    ### same as: rs.DeleteObjects( rs.AllObjects() )

rs.EnableRedraw(0)
rs.Redraw()

if 1:
    print "        /\\        "
    print "       / |\\       "
    print " TETR /__|_\\ EDER  h=a/3.0*(6.0**0.5) "
    print "_____/   |  \\______vulgo: \"hoehe ist gleich a durch 3 - mal wurzel aus 6\"\n"


pointsX = [[0, 3, 0], [3, 0, 0], [5, 3, 3]]
if 0:
    ptA = dm.pntRandVec(-3, 3)
    ptB = dm.pntRandVec(-3, 3)
    ptX = dm.pntRandVec(-3, 3)
    dm.pointsX = [ptA, ptB, ptX]  ### check in another TAB !
    pointsX = [ptA, ptB, ptX]

tetraCoords = dm.getTetraCoords( points=pointsX, flipH=1, flipAB=1, drawTetra=1, drawAll=1 )
#tetraCoords = dm.getTetraCoords( points=pointsX, flipH=0, flipAB=1, drawTetra=0, drawAll=0 )
#tetraCoords = dm.getTetraCoords( tetraCoords[0], flipH=0, flipAB=1, drawTetra=1, drawAll=0 )

print tetraCoords[0]
print len(tetraCoords)
print len(tetraCoords[0])

rs.AddCurve( tetraCoords[0], 1 )
rs.AddSrfPt(  tetraCoords[0] )

tetraCoords = dm.getTetraCoords( tetraCoords[0], flipH=0, flipAB=1, drawTetra=1, drawAll=2 )
#rs.AddSrfPt(  tetraCoords[1] )
tetraCoords = dm.getTetraCoords( tetraCoords[1], flipH=0, flipAB=0, drawTetra=1, drawAll=1 )

print tetraCoords[0]
print tetraCoords[1]

if 0: ### check & test & visualize
    for i, FaceCoordList in enumerate(tetraCoords):
        print "face", i, 
        print FaceCoordList
    print
    for i, cor in enumerate(tetraCoords[0]):
        print "cor", i, 
        print cor

    #rs.DeleteObjects( rs.ObjectsByType( 1 + 8192 ) )
    #dm.eA()
    rs.AddSrfPt(tetraCoords[2])         ### ! achtung! boeze surface !
    rs.AddPoints( tetraCoords[1] )      ### 
    rs.ObjectColor( rs.AllObjects()[:4], [0,200,200] )

rs.ZoomExtents()

#_____________________________here you go:
#_________________________________________







#_________________________________________
#____________________________:here you end


###############################################
#___4_lazy_experts: automated capture to LW P:/
if 1:
    rs.ZoomExtents()
    rs.Command("-zoom Factor 0.95 enter", 0) # decrease zoom for better framing
    rs.Redraw()
    if  1:
        path = "P:/ue_04/images/"
        name = "tst.png"
        rs.Command("-viewCaptureToFile Width=480  Height=360  Scale=1.5 DrawCPlaneAxes=No TransparentBackground=Yes "+path+name, 0)
        # .jpg and Scale=4 for webSite submission
        name = "tst_"+str(int(time.time()))+".jpg"
        rs.Command("-viewCaptureToFile Width=480  Height=360  Scale=4 TransparentBackground=No  "+path+name, 0)
