import jsdai.SMachining_schema.*;
import jsdai.dictionary.EBoolean_type;
import jsdai.lang.*;

public class ExampleDrillHole {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws SdaiException
	{
		// TODO Auto-generated method stub
		SdaiSession session = SdaiSession.openSession();
		session.startTransactionReadWriteAccess();
		SdaiRepository repository = session.createRepository("", null);
		repository.openRepository();
		SdaiModel model = repository.createSdaiModel("DemoSTEP_NC", SMachining_schema.class);
		model.startReadWriteAccess();
		
						
		EProject project = (EProject)model.createEntityInstance(EProject.class);
		project.setIts_id(null, "Bohrung");
						
		EWorkplan workplan = (EWorkplan)model.createEntityInstance(EWorkplan.class);
		workplan.setIts_id(null, "Arbeitsplan");
		
		EWorkpiece workpiece = (EWorkpiece)model.createEntityInstance(EWorkpiece.class);
		workpiece.setIts_id(null, "Bauteil1");
		
		EMachining_workingstep machining_workingstep = (EMachining_workingstep)model.createEntityInstance(EMachining_workingstep.class);
		machining_workingstep.setIts_id(null, "Bohrung");
		
		ESetup setup = (ESetup)model.createEntityInstance(ESetup.class);
		setup.setIts_id(null, "Aufspannung_Bohrung");
		
		EMaterial material = (EMaterial)model.createEntityInstance(EMaterial.class);
		material.setMaterial_identifier(null, "St50");
		material.setStandard_identifier(null, "Stahl");
		
		EProperty_parameter property_parameter = (EProperty_parameter)model.createEntityInstance(EProperty_parameter.class);
		property_parameter.setParameter_name(null, "E210000 N/MM^2");
		
		EBlock block = (EBlock)model.createEntityInstance(EBlock.class);
		block.setName(null, "Block");
		
		EAxis2_placement_3d axis2_placement_3d = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d.setName(null, "umschl. Korper relativ zum werkstuk");		
		
		ECartesian_point cartesian_point = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point.setName(null, "");
		
		EDirection direction = (EDirection)model.createEntityInstance(EDirection.class);
		direction.setName(null, "");
		
		EDirection direction1 = (EDirection)model.createEntityInstance(EDirection.class);
		direction1.setName(null, "");
		
		EPlane plane = (EPlane)model.createEntityInstance(EPlane.class);
		plane.setName(null, "");
		
		EAxis2_placement_3d axis2_placement_3d1 = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d1.setName(null, "");
		
		ECartesian_point cartesian_point1 = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point1.setName(null, "");
		
		ERound_hole round_hole = (ERound_hole)model.createEntityInstance(ERound_hole.class);
		round_hole.setIts_id(null, "Bohrung 20mm");
		
		EDrilling drilling = (EDrilling)model.createEntityInstance(EDrilling.class);
		drilling.setIts_id(null, "Bohrung 20mm");
		
		ECutting_tool cutting_tool = (ECutting_tool)model.createEntityInstance(ECutting_tool.class);
		cutting_tool.setIts_id(null, "Bohrer 20mm");
		
		EBoring_tool boring_tool = (EBoring_tool)model.createEntityInstance(EBoring_tool.class);
        
		ETool_dimension tool_dimension = (ETool_dimension)model.createEntityInstance(ETool_dimension.class);
		
		EMilling_technology milling_technology = (EMilling_technology)model.createEntityInstance(EMilling_technology.class);
		
		EMilling_machine_functions milling_machine_functions = (EMilling_machine_functions)model.createEntityInstance(EMilling_machine_functions.class);
		
		EAxis2_placement_3d axis2_placement_3d2 = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d2.setName(null, "Bohrung");
		
		ECartesian_point cartesian_point2 = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point2.setName(null, "");
		
		EDirection direction2 = (EDirection)model.createEntityInstance(EDirection.class);
		direction2.setName(null, "");
		
		EDirection direction3 = (EDirection)model.createEntityInstance(EDirection.class);
		direction3.setName(null, "");
		
		EToleranced_length_measure toleranced_length_measure = (EToleranced_length_measure)model.createEntityInstance(EToleranced_length_measure.class);
		toleranced_length_measure.setTheoretical_size(null,60.000);
		
		EToleranced_length_measure toleranced_length_measure1 = (EToleranced_length_measure)model.createEntityInstance(EToleranced_length_measure.class);
		toleranced_length_measure1.setTheoretical_size(null,20.000);
		
		EThrough_bottom_condition through_bottom_condition = (EThrough_bottom_condition)model.createEntityInstance(EThrough_bottom_condition.class);
		
		EAxis2_placement_3d axis2_placement_3d3 = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d3.setName(null, "Nullpunkt relativ zum Maschinennullpunkt");
		
		ECartesian_point cartesian_point3 = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point3.setName(null, "");
		
		EDirection direction4 = (EDirection)model.createEntityInstance(EDirection.class);
		direction4.setName(null, "");
		
		EDirection direction5 = (EDirection)model.createEntityInstance(EDirection.class);
		direction5.setName(null, "");
		
		EPlane plane1 = (EPlane)model.createEntityInstance(EPlane.class);
		plane1.setName(null, "");
		
		EAxis2_placement_3d axis2_placement_3d4 = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d4.setName(null, "Sicherheitsebene");
		
		ECartesian_point cartesian_point4 = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point4.setName(null, "");
		
		//workpiece_position não existe no schema
		//foi substituido por workpiece_setup
		EWorkpiece_setup workpiece_setup = (EWorkpiece_setup)model.createEntityInstance(EWorkpiece_setup.class);
		
		EAxis2_placement_3d axis2_placement_3d5 = (EAxis2_placement_3d)model.createEntityInstance(EAxis2_placement_3d.class);
		axis2_placement_3d5.setName(null, "Werkstucknullpkt");
		
		ECartesian_point cartesian_point5 = (ECartesian_point)model.createEntityInstance(ECartesian_point.class);
		cartesian_point5.setName(null, "");
		
		EDirection direction6 = (EDirection)model.createEntityInstance(EDirection.class);
		direction6.setName(null, "");
		
		EDirection direction7 = (EDirection)model.createEntityInstance(EDirection.class);
		direction7.setName(null, "");
		
		//atributos
		axis2_placement_3d.setLocation(null, cartesian_point);
		axis2_placement_3d.setAxis(null, direction);
		axis2_placement_3d.setRef_direction(null, direction1);

		block.setPosition(null, axis2_placement_3d);
		block.setX(null, 110.000);
		block.setY(null, 110.000);
		block.setZ(null, 80.000);

		workpiece.setIts_material(null, material);
		workpiece.setGlobal_tolerance(null, 0.01);
		workpiece.setIts_bounding_geometry(null, block);

		axis2_placement_3d1.setLocation(null, cartesian_point1);

		plane.setPosition(null, axis2_placement_3d1);

		axis2_placement_3d2.setLocation(null, cartesian_point2);
		axis2_placement_3d2.setAxis(null, direction2);
		axis2_placement_3d2.setRef_direction(null, direction3);

		milling_technology.setFeedrate(null, 0.01);
		milling_technology.setSynchronize_spindle_with_feed(null, false);
		milling_technology.setInhibit_feedrate_override(null, false);
		milling_technology.setInhibit_spindle_override(null, false);

		milling_machine_functions.setCoolant(null, true);
		milling_machine_functions.setMist(null, true);
		milling_machine_functions.setThrough_spindle_coolant(null, false);
		milling_machine_functions.setChip_removal(null, true);

		drilling.setRetract_plane(null, 10.000);
		drilling.setIts_technology(null, milling_technology);
		drilling.setIts_machine_functions(null, milling_machine_functions);

		round_hole.setIts_workpiece(null, workpiece);
		round_hole.setFeature_placement(null, axis2_placement_3d2);
		round_hole.setDiameter(null, toleranced_length_measure1);
		round_hole.setBottom_condition(null, through_bottom_condition);

		machining_workingstep.setIts_secplane(null, plane);
		machining_workingstep.setIts_feature(null, round_hole);
		machining_workingstep.setIts_operation(null, drilling);

		axis2_placement_3d3.setLocation(null, cartesian_point3);
		axis2_placement_3d3.setAxis(null, direction4);
		axis2_placement_3d3.setRef_direction(null, direction5);

		axis2_placement_3d4.setLocation(null, cartesian_point4);

		plane1.setPosition(null, axis2_placement_3d4);

		setup.setIts_origin(null, axis2_placement_3d3);
		setup.setIts_secplane(null, plane1);
		
		
		workplan.setIts_setup(null, setup);

		project.setMain_workplan(null, workplan);

		tool_dimension.setDiameter(null, 20.000);
		tool_dimension.setTool_top_angle(null, 0.00);

		boring_tool.setDimension(null, tool_dimension);
		boring_tool.setNumber_of_teeth(null, 2);
		boring_tool.setHand_of_cut(null, EHand.RIGHT);
		boring_tool.setCoolant_through_tool(null, false);
		boring_tool.setRetract_movement_forbidden(null, true);
		
		workpiece_setup.setIts_workpiece(null, workpiece);
		workpiece_setup.setIts_origin(null, axis2_placement_3d5);
		
		axis2_placement_3d5.setLocation(null, cartesian_point5);
		axis2_placement_3d5.setAxis(null, direction6);
		axis2_placement_3d5.setRef_direction(null, direction7);
		
		cutting_tool.setIts_tool_body(null, boring_tool);
		cutting_tool.setOverall_assembly_length(null, 75.000);
		
		//coordenadas para "cartesian_point" e "direction"
		A_double p = cartesian_point.createCoordinates(null);
		p.addByIndex(1, -5.0);
		p.addByIndex(2, -5.0);
		p.addByIndex(3, -5.0);
		
		A_double p1 = cartesian_point1.createCoordinates(null);
		p1.addByIndex(1, 0.0);
		p1.addByIndex(2, 0.0);
		p1.addByIndex(3, 60.0);
		
		A_double p2 = cartesian_point2.createCoordinates(null);
		p2.addByIndex(1, 50.0);
		p2.addByIndex(2, 50.0);
		p2.addByIndex(3, 60.0);
		
		A_double p3 = cartesian_point3.createCoordinates(null);
		p3.addByIndex(1, 20.0);
		p3.addByIndex(2, 40.0);
		p3.addByIndex(3, 120.0);
		
		A_double p4 = cartesian_point4.createCoordinates(null);
		p4.addByIndex(1, 0.0);
		p4.addByIndex(2, 0.0);
		p4.addByIndex(3, 65.0);
		
		A_double p5 = cartesian_point5.createCoordinates(null);
		p5.addByIndex(1, 0.0);
		p5.addByIndex(2, 0.0);
		p5.addByIndex(3, 0.0);
		
		A_double d = direction.createDirection_ratios(null);
		d.addByIndex(1, 0.0);
		d.addByIndex(2, 0.0);
		d.addByIndex(3, 1.0);
		
		A_double d1 = direction1.createDirection_ratios(null);
		d1.addByIndex(1, 1.0);
		d1.addByIndex(2, 0.0);
		d1.addByIndex(3, 0.0);
		
		A_double d2 = direction2.createDirection_ratios(null);
		d2.addByIndex(1, 0.0);
		d2.addByIndex(2, 0.0);
		d2.addByIndex(3, 1.0);
		
		A_double d3 = direction3.createDirection_ratios(null);
		d3.addByIndex(1, 1.0);
		d3.addByIndex(2, 0.0);
		d3.addByIndex(3, 0.0);
		
		A_double d4 = direction4.createDirection_ratios(null);
		d4.addByIndex(1, 0.0);
		d4.addByIndex(2, 0.0);
		d4.addByIndex(3, 1.0);
		
		A_double d5 = direction5.createDirection_ratios(null);
		d5.addByIndex(1, 1.0);
		d5.addByIndex(2, 0.0);
		d5.addByIndex(3, 0.0);
		
		A_double d6 = direction6.createDirection_ratios(null);
		d6.addByIndex(1, 0.0);
		d6.addByIndex(2, 0.0);
		d6.addByIndex(3, 1.0);
		
		A_double d7 = direction7.createDirection_ratios(null);
		d7.addByIndex(1, 1.0);
		d7.addByIndex(2, 0.0);
		d7.addByIndex(3, 0.0);
		
		//Atributos tipo "LIST"
		
		AWorkpiece_setup workpiece_setup_a = setup.createIts_workpiece_setup(null);
		workpiece_setup_a.addByIndex(1, workpiece_setup);
		
		//Atributos tipo "SET"
		AWorkpiece work = project.createIts_workpieces(null);
		work.addUnordered(workpiece, null);
		
		AExecutable machining = workplan.createIts_elements(null);
		machining.addUnordered(machining_workingstep, null);
		
		ACartesian_point cart = workpiece.createClamping_positions(null);
				
		AProperty_parameter property = material.createMaterial_property(null); 
		property.addUnordered(property_parameter, null); 
		
		AMachining_operation dril = round_hole.createIts_operations(null);
		dril.addUnordered(drilling, null);
		
		ACutting_component cut = cutting_tool.createIts_cutting_edge(null);
				
		A_string id = milling_machine_functions.createAxis_clamping(null);
		AProperty_parameter prop = milling_machine_functions.createOther_functions(null);

		repository.exportClearTextEncoding("STEP-NC File.p21");
		session.closeSession();
		System.out.println("====== DONE ======");
	}
	
}
