/* * Copyright (c) 1991-2023 by STEP Tools Inc. * All Rights Reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation is hereby granted, provided that this copyright * notice and license appear on all copies of the software. * * STEP TOOLS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. STEP TOOLS * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. * * Author: Dave Loffredo (loffredo@steptools.com) */ #include #include "geometry_utils.h" #include "context_utils.h" #include "unit_utils.h" #include "make_polyshell.h" stp_shape_representation * create_empty_product_with_geometry( RoseDesign * d ); int main(int /*argc*/, char** /*argv*/) { stplib_init(); // initialize STEP class library /* Create a RoseDesign to hold the instance data */ const char * output_name = "output_file"; RoseDesign * d = new RoseDesign (output_name); // Declare it as an AP214 file stplib_put_schema (d, stplib_schema_ap214); // Give the design some Part 21 header information d-> initialize_header(); d-> header_name()-> originating_system ("Geometry Demo"); d-> header_description()-> description ()-> add ("Empty Shape Representation Sample File"); // Set as the current design. Objects created using the "pnew" // macro go here. We can create objects in a specific design // using "pnewIn(design)", but is less convenient to write. // ROSE.useDesign(d); // CREATE A SWEPT POLYGON SHELL WITH HOLES - pass in a list of 2D // points and a thickness. Use those points to define a polygonal // face in the XY plane, define another one offset by thickness in // the -Z direction, then sew everything up as a closed brep // shell. // // The points should be clockwise as you look down at the top // face. double thickness = 1; ListOfstp_cartesian_point xypts; xypts.add(make_point(d, 0, 5)); xypts.add(make_point(d, -5, 10)); xypts.add(make_point(d, -5, -5)); xypts.add(make_point(d, 5, -5)); xypts.add(make_point(d, 5, 10)); // back to first point 0,5 // Pass back the shell. Pass back the top and bottom face in case // we want to define any holes in them. stp_advanced_face * top = 0; stp_advanced_face * bottom = 0; stp_closed_shell * shell = 0; make_polygon_shell ( &shell, &top, &bottom, d, &xypts, thickness ); // Add a round hole r=1 at 2.5,5 and another at -2.5, 5 // The holes must not intersect the edge of the part or // another hole. make_circular_hole (shell, top, bottom, 2.5, 5, 1, thickness); make_circular_hole (shell, top, bottom, -2.5, 5, 1, thickness); // add a rectangular hole through the sheet. The holes must not // intersect the edge of the part or another hole. xypts.emptyYourself(); xypts.add(make_point(d, 4, 0)); xypts.add(make_point(d, -4, 0)); xypts.add(make_point(d, -4, -2)); xypts.add(make_point(d, 4, -2)); // back to first point 4,0 make_polygon_hole (shell, top, bottom, &xypts, thickness); // Create an empty shape rep and a basic product around that. // Make a brep solid to contain the shell and add to the shape // representation. stp_shape_representation * shape = create_empty_product_with_geometry(d); stp_manifold_solid_brep * brep = pnewIn(d) stp_manifold_solid_brep; brep->name (""); brep->outer (shell); shape->items()->add (brep); d-> save(); return 0; } //---------------------------------------- // CREATE A PRODUCT AND SHAPE REP - Product structure and attached // geometry is explained in detail by the GEOMETRY sample program. // Adjust this boilerplate to meet your needs. // stp_shape_representation * create_empty_product_with_geometry( RoseDesign * d ) { stp_product* pr = pnewIn(d) stp_product(); // Fill in the part number, name, and description. pr-> id ("1234-K789"); pr-> name ("widget"); pr-> description ("a fictional product"); pr-> frame_of_reference()-> add (make_product_context()); stp_product_definition_formation* pdf = pnewIn(d) stp_product_definition_formation; pdf-> of_product(pr); pdf-> id ("1.0"); pdf-> description ("first version of our widget"); stp_product_definition* pd = pnewIn(d) stp_product_definition(); pd-> formation (pdf); pd-> id ("design"); pd-> description ("example product_definition"); pd-> frame_of_reference (make_pdef_context()); //---------------------------------------- // CREATE AND ATTACH A SHAPE REPRESENTATION // // Create the shape representation. Use the advanced brep subtype // since we are making BREP geometry. stp_advanced_brep_shape_representation * rep = pnewIn(d) stp_advanced_brep_shape_representation; stp_product_definition_shape * pds = pnewIn(d) stp_product_definition_shape; pds-> name (""); pds-> definition (pnewIn(d) stp_characterized_definition); pds-> definition ()-> _characterized_product_definition (pnewIn(d) stp_characterized_product_definition); pds-> definition ()-> _characterized_product_definition()-> _product_definition (pd); stp_shape_definition_representation * sdr = pnewIn(d) stp_shape_definition_representation; sdr-> definition (pnewIn(d) stp_represented_definition); sdr-> definition ()-> _property_definition (pds); sdr-> used_representation (rep); stp_representation_context * rep_ctx = make_geometry_context ( ROSE.design(), // location to create the context "ID1", // some name for the context 3, // number of dimensions, ie 3D make_mm_unit(), // length unit for geometry make_degree_unit(), // angle unit for geometry make_steradian_unit(), // solid angle unit 1e-6 // global uncertainty (optional) ); rep-> name (""); rep-> context_of_items (rep_ctx); // Done return rep; }