*#If(IntvData(Use_Digicon,Int)==1)
*#If(GenData(Use_Digicon,Int)==1)
*If(GenData(Use_Digicon,Int)==1)
// digicon - Update elements age to simulate printing process

*# // User function.
*loop materials *NotUsed
*If(strcmp(MatProp(Material_Prototype),"CCDigiconTrack")==0)
*# //Use_for_Material = *MatProp(Use_for_Material)
*# // enabled = *MatProp(Enabled,Int)
*If(MatProp(Enabled,Int)==1)
// CCDigiconTrack : matprop0 = *MatProp(0),  Use_for_Material = *MatProp(Use_for_Material)

*If(strcmp(MatProp(Defined_by),"Construction_time")==0)
ELEMENT GROUP ID *tcl(TK_WriteMaterialNumberVSGroupID *MatProp(Use_for_Material)) 
  GROUP_CONSTRUCT_TIME *MatProp(Construction_time,Real) ;
  
*Else

*#include ..\include.src.bas\CCMultiLinearFunction.bas
*Set Var oMujMat=tcl(TK_FindMaterialNumber *MatProp(0) "CCDigiconTrack")
// CCDigiconTrack MatId: *oMujMat
// SET TRANSIENT TIME INCREMENT = 5 

*If(strcmp(MatProp(Definition_of_trajectory),"Trajectory_csv")==0)
MACRO_JOINT COORDINATES            // Printing polygon preparation  // If some strange chars below, please resave the csv file in unicode.
*tcl(DejDigiMacroJoint 0 *MatProp(Printing_trajectory_csv_file) *oMujMat *MatProp(Type_of_trajectory_csv))

//Use_for_Material = *MatProp(Use_for_Material)
*#Set Var oMujMatUse=tcl(TK_FindMaterialNumber *MatProp(Use_for_Material) *MatProp(0))
*# // oMujMatUse = *oMujMatUse
*#include ..\include.src.bas\CurrentElementgroupID.bas
*#
*#Set Var groupID=Operation(ElemsMat*IncrMaterialID+CurrentType)
*#tcl(TK_WriteMaterialNumberVSGroupID *MatProp(Use_for_Material))

*EndIf  
*Intformat "%i"
SELECTION "PRINTED_GROUPS_IDS_NAME_*oMujMat" LIST *tcl(TK_WriteMaterialNumberVSGroupID *MatProp(Use_for_Material));
SET negligible_element_contribution_coeff 0.0001
  
 UPDATE_ELEMENT_CONSTRUCT_TIME
*If(strcmp(MatProp(Definition_of_trajectory),"Trajectory_csv")==0) 
*If(strcmp(MatProp(Type_of_trajectory_csv),"Bottom_right_of_printing_path")==0) 
    TRACK_NODES "TRACK_NODES_IDS_NAME_*oMujMat"     
*ElseIf(strcmp(MatProp(Type_of_trajectory_csv),"Top_center_of_printing_path-first_layer_only")==0) 
    TRACK_MNODES "TRACK_MNODES_IDS_NAME_*oMujMat"
*ElseIf(strcmp(MatProp(Type_of_trajectory_csv),"Top_center_of_printing_path-all_layers")==0) 
    TRACK_MNODES_ALL "TRACK_MNODES_IDS_NAME_*oMujMat"    
*Else   
    // unknown TRACK_NODES  *MatProp(Type_of_trajectory_csv)
*EndIf
*ElseIf(strcmp(MatProp(Definition_of_trajectory),"Trajectory_Gcode")==0)
*If(strcmp(MatProp(Type_of_trajectory_gcode),"First_layer_only")==0) 
    TRACK_MNODES "TRACK_MNODES_IDS_NAME_*oMujMat"    
*ElseIf(strcmp(MatProp(Type_of_trajectory_gcode),"All_layers")==0) 
    TRACK_MNODES_ALL "TRACK_MNODES_IDS_NAME_*oMujMat"  
*Else   
    // unknown TRACK_NODES  *MatProp(Type_of_trajectory_gcode)
*EndIf
*Else
    // unknown Definition_of_trajectory  *MatProp(Definition_of_trajectory)
*EndIf
    GROUPS "PRINTED_GROUPS_IDS_NAME_*oMujMat"
    VELOCITY *MatProp(Printing_head_velocity,Real)
    LAYER THICKNESS *MatProp(Printed_layer_height,Real)  
    WIDTH *MatProp(Printed_layer_width,Real)
*If(strcmp(MatProp(Printing_direction),"3D_X")==0) 
    DIRECTION 1. 0. 0.     
*ElseIf(strcmp(MatProp(Printing_direction),"3D_Y")==0) 
    DIRECTION 0. 1. 0.
*ElseIf(strcmp(MatProp(Printing_direction),"3D_Z")==0) 
    DIRECTION 0. 0. 1.
*ElseIf(strcmp(MatProp(Printing_direction),"2D_X")==0) 
    DIRECTION 1. 0.
*ElseIf(strcmp(MatProp(Printing_direction),"2D_Y")==0) 
    DIRECTION 0. 1.
*ElseIf(strcmp(MatProp(Printing_direction),"Vector")==0) 
    DIRECTION *MatProp(Printing_direction_vector_x,Real) *MatProp(Printing_direction_vector_y,Real) *MatProp(Printing_direction_vector_z,Real)
*Else
    // unknown DIRECTION  *MatProp(Printing_direction)
*EndIf
    START_TIME *MatProp(Printing_START_TIME)
    TIME_BETWEEN_LAYERS *MatProp(Printing_TIME_BETWEEN_LAYERS)
*If(MatProp(ALLOW_REVERSE_PRINTING,Int)==1)
    ALLOW_REVERSE_PRINTING
*EndIf
*If(MatProp(OPTIMIZE_TRACK,Int)==1)
*If(strcmp(MatProp(Optimize_track_method),"2_OPT")==0) 
    USE_2_OPT *\     
*ElseIf(strcmp(MatProp(Optimize_track_method),"3_OPT")==0) 
    USE_3_OPT *\   
*ElseIf(strcmp(MatProp(Optimize_track_method),"4_OPT")==0) 
    USE_4_OPT *\   
*ElseIf(strcmp(MatProp(Optimize_track_method),"5_OPT")==0) 
    USE_5_OPT *\ 
*Else
*EndIf
  OPTIMIZE_TRACK
*EndIf
    MIN_REL_HEIGHT *MatProp(MIN_REL_HEIGHT)
    MAX_REL_HEIGHT *MatProp(MAX_REL_HEIGHT)
*If(MatProp(Active_DEVIATION_DELAY_FNC,Int)==1)
*Set Var oMujMat=tcl(TK_FindMaterialNumber *MatProp(DEVIATION_DELAY_FNC) "Digicon-deviaion-delay")
    DEVIATION_DELAY_FNC *Operation(25250000+oMujMat)
*EndIf   
*If(strcmp(MatProp(Definition_of_trajectory),"Trajectory_Gcode")==0) 
    IMPORT_TRACK_GCODE "*MatProp(Printing_trajectory_gcode_file)"
*EndIf

    // ADD_CONSTR_TIME   //Increment start_time  by the time needed to print previous elements
    // VERBOSE      //Verbose partial steps of the above optimization
    // TRACK_OFFSET offset   //Set track offset used to calculate layer id. It is usually used in cooperation with ADD_MAX_CONSTR_TIME. By default, offset =0.
   EXECUTE

*EndIf   
*# *If(oMinIndexElemGroups<oMaxIndexElemGroups)
*#Load TEMPERATURE GROUP *oMinIndexElemGroups TO *oMaxIndexElemGroups  HISTORY IMPORT
*#*Else
*#Load TEMPERATURE GROUP *OneGroupID  HISTORY IMPORT
*#*EndIf   
   
SELECTION "SOLID_BOX_ELEMENTS" from 1 to *MaxElemsNum  
SELECTION "SOLID_BOX_ELEMENTS" CONSTRUCT_TIME_DEPENDENT_ACTIVE GROUP *tcl(TK_WriteMaterialNumberVSGroupID *MatProp(Use_for_Material));

*EndIf
*EndIf
*End materials

*EndIf
