/* $RCSfile: geometry.cxx,v $ * $Revision: 1.8 $ $Date: 2011/12/16 21:34:52 $ * Auth: Dave Loffredo (loffredo@steptools.com) * * Copyright (c) 1991-2012 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. */ #include #include #include #include "geometry_utils.h" #include "context_utils.h" #include "unit_utils.h" // BUILD GEOMETRY - Build a product structure with an empty shape // representation to hold our geometry. This program builds all of // the STEP backbone entities that go into creating a product with // geometry. // // Some of the details in the product structure differ from // AP to AP, but most of this // This program creates the data set and saves it as a STEP Part 21 // file called "output_file.stp". This is a text file, so you can // look at it with a text editor or the STEP Part 21 file browser to // see how the information is represented. stp_shape_representation * create_empty_product_with_geometry(); int main(int argc, char* argv[]) { /* Force optimizing linkers to bring in all C++ classes */ stp_schema_force_load(); rose_p28_init(); // support xml read/write /* Create a RoseDesign to hold the instance data */ const char * output_name = "output_file"; RoseDesign * design = new RoseDesign (output_name); /* Give the design some Part 21 header information */ design-> initialize_header(); design-> header_name()-> originating_system ("Geometry Demo"); design-> 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(design); create_empty_product_with_geometry(); // Uncomment the following to write as zip compressed P28 XML // rather than Part 21 ASCII. Change the string "p28-raw" to // write uncompressed XML. The default is "p21". // // design-> format ("p28"); design-> save(); return 0; } stp_shape_representation * create_empty_product_with_geometry() { //---------------------------------------- // CREATE THE PRODUCT - // Create a product object to represent our part. stp_product* pr = pnew stp_product(); // Fill in the part number, name, and description. pr-> id ("1234-K789"); pr-> name ("widget"); pr-> description ("a fictional product"); // The context information is boilerplate information that is the // same for all files defined by a particular AP, although it does // change a bit from AP to AP. See the context_utils.cxx file for // the specifics. // pr-> frame_of_reference()-> add (make_product_context()); // The product needs a product definition formation to describe // the version with an id and description // stp_product_definition_formation* pdf = pnew stp_product_definition_formation; pdf-> of_product(pr); pdf-> id ("1.0"); pdf-> description ("first version of our widget"); // The PDF needs a product definition. This describes a the // version from a particular point of view in the life cycle, so // most APs only have one per PDF, but some APs use several. // stp_product_definition* pd = pnew stp_product_definition(); pd-> formation (pdf); pd-> id ("design"); pd-> description ("example product_definition"); // The context information is boilerplate information as above in // the product. See the context_utils.cxx file for the specifics. // pd-> frame_of_reference (make_pdef_context()); //---------------------------------------- // Depending on the application protocol, the product, PDF, and PD // may also need some configuration management information, like a // design owner, approvals, etc. For simplicity, we do not create // any of that here, but a real application would. //---------------------------------------- // CREATE AND ATTACH A SHAPE REPRESENTATION // // The geometric description of product shape is attached to the // product_definition as a property. The way properties work in // STEP is with a series of objects: // // (owner of the property) // <- property_definition // <- property_definition_representation -> // representation -> // representation_items // // The property_definition identifies the property type while the // representation + rep items describe the property value. The // property_definition_representation relates the property with // its value description. In this way STEP can describe the value // of a particular property in several different ways if needed // (such as a brep version of geometry and a facetted version) // // The geometric shape of a product uses some special subtypes of // the things above to make the shape property more distinctive in // the data set. //---------------------------------------- // Create the shape representation. This is the container that // holds geometry items. Normally we would create some subtype of // shape rep like advanced_brep_shape_representation to indicate a // particular style of geometry/topology description. // stp_shape_representation * rep = pnew stp_shape_representation; // Give the product a shape property. Product_definition_shape is // a subtype of property_definition used for shape properties. It // refers to the product through the product_definition. // stp_product_definition_shape * pds = pnew stp_product_definition_shape; pds-> name (""); pds-> definition (pnew stp_characterized_definition); pds-> definition ()-> _characterized_product_definition (pnew stp_characterized_product_definition); pds-> definition ()-> _characterized_product_definition()-> _product_definition (pd); // Attach the shape representation to the property. The // shape_definition_representation subtype is used for shape // properties and the property_definition_representation supertype // is used for other types of properties. // stp_shape_definition_representation * sdr = pnew stp_shape_definition_representation; // Newer APs use a represented_definition select here. sdr-> definition (pds); sdr-> used_representation (rep); //---------------------------------------- // INITIALIZE THE SHAPE REPRESENTATION // // The STEP geometry definitions in ISO 10303-42 are unit-less, so // we must give the shape representation context information that // identifies the units, the number of dimensions (2 or 3), and // possibly some geometric uncertainty (how close two points can // be before they are considered the same). // // Refer to geometry_utils.cxx for specifics on the context. // Refer to unit_utils.cxx for specifics on the units. // stp_representation_context * rep_ctx = make_geometry_context ( ROSE.design(), // location to create the context "ID1", // some name for the context 2, // number of dimensions, ie 2D make_mm_unit(), // length unit for geometry make_degree_unit() // angle unit for geometry ); rep-> name (""); rep-> context_of_items (rep_ctx); // Now we would add the geometry and topology items that define // the product shape. For an example, create an axis placement // with a location but no direction vectors. // // Since AP201 is 2D explicit geometry, we create a 2D point and // axis placement. In other APs we usually create 3D ones. // stp_cartesian_point* p1 = pnew stp_cartesian_point; p1-> name(""); p1-> coordinates()->add(1.1); p1-> coordinates()->add(2.2); stp_axis2_placement_2d* ap2d = pnew stp_axis2_placement_2d ( "orientation", p1, 0 ); // Add it to the representation rep-> items()-> add (ap2d); // Done return rep; }