ricosjp / truck

Truck is a Rust CAD Kernel.
Apache License 2.0
1.03k stars 53 forks source link

truck_stepio::out issue: missing type qualifiers and extra parentheses #84

Open elgar328 opened 1 week ago

elgar328 commented 1 week ago

I ran the tutorial code to generate the cube.step file, and below is a portion of the file.

ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('Shape Data from Truck'), '2;1');
FILE_NAME('', '2024-11-22 06:23:22.934453', (('')), (('')), 'truck', '', '');
FILE_SCHEMA(('ISO-10303-042'));
ENDSEC;
DATA;
#1 = APPLICATION_PROTOCOL_DEFINITION('international standard', 'automotive_design', 2000, #2);
#2 = APPLICATION_CONTEXT('core data for automotive mechanical design processes');
#3 = SHAPE_DEFINITION_REPRESENTATION(#4, #10);
#4 = PRODUCT_DEFINITION_SHAPE('','', #5);
#5 = PRODUCT_DEFINITION('design','', #6, #9);
#6 = PRODUCT_DEFINITION_FORMATION('','', #7);
#7 = PRODUCT('','','', (#8));
#8 = PRODUCT_CONTEXT('', #2, 'mechanical');
#9 = PRODUCT_DEFINITION_CONTEXT('part definition', #2, 'design');
#10 = ADVANCED_BREP_SHAPE_REPRESENTATION('', (#16), #11);
#11 = (
    GEOMETRIC_REPRESENTATION_CONTEXT(3) 
    GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#15))
    GLOBAL_UNIT_ASSIGNED_CONTEXT((#12, #13, #14))
    REPRESENTATION_CONTEXT('Context #1', '3D Context with UNIT and UNCERTAINTY')
);
#12 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
#13 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
#14 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
#15 = UNCERTAINTY_MEASURE_WITH_UNIT(1.0E-6, #12, 'distance_accuracy_value','confusion accuracy');
#16 = MANIFOLD_SOLID_BREP('', #17);

I imported this file into the FE analysis software and observed two warnings.

To eliminate the warnings, I manually modified the contents of the STEP file as follows:

FILE_NAME('', '2024-11-22 06:23:22.934453', (('')), (('')), 'truck', '', '');
FILE_NAME('', '2024-11-22 06:23:22.934453', (''), (''), 'truck', '', '');

#15 = UNCERTAINTY_MEASURE_WITH_UNIT(1.0E-6, #12, 'distance_accuracy_value','confusion accuracy');
#15 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.0E-6), #12, 'distance_accuracy_value','confusion accuracy');

I removed one set of parentheses, changing (('')), (('')) to (''), (''), and added a type() qualifier by changing 1.0E-6 to LENGTH_MEASURE(1.0E-6).

Is it possible to solve this issue?

elgar328 commented 1 week ago

I’m currently using it as a temporary workaround.

fn save_step(solid: &Solid, path: &str) {
    // compress solid data.
    let compressed = solid.compress();
    // step format display
    let display = CompleteStepDisplay::new(StepModel::from(&compressed), Default::default());
    // content of step file
    let step_string: String = display.to_string();
    let step_string = repair_step_syntax(step_string);
    std::fs::write(path, &step_string).unwrap();
}

fn repair_step_syntax(input: String) -> String {
    let mut result = String::new();

    for line in input.lines() {
        // Handle FILE_NAME
        if line.starts_with("FILE_NAME") {
            let modified_line = line.replace("((''))", "('')");
            result.push_str(&modified_line);
        }
        // Handle UNCERTAINTY_MEASURE_WITH_UNIT
        else if line.contains("UNCERTAINTY_MEASURE_WITH_UNIT(") {
            let start_idx = line.find("UNCERTAINTY_MEASURE_WITH_UNIT(").unwrap();
            let end_idx = line[start_idx..].find(",").unwrap() + start_idx;

            let measure = &line[start_idx + "UNCERTAINTY_MEASURE_WITH_UNIT(".len()..end_idx];
            let modified_measure = format!("LENGTH_MEASURE({})", measure);

            let modified_line = line.replace(measure, &modified_measure);
            result.push_str(&modified_line);
        } else {
            // Add other lines as is
            result.push_str(line);
        }

        result.push('\n');
    }

    result
}