/* $RCSfile: product.cxx,v $ * $Revision: 1.2 $ $Date: 2007/08/29 21:48:35 $ * Auth: Dave Loffredo (loffredo@steptools.com) * * Copyright (c) 1991-2007 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 PRODUCT - Build a product structure with an empty shape // representation. AP239 does not containg any of the STEP geometric // entities, so the representation would contain something else, but // this program builds all of the STEP backbone entities that go into // creating a product with geometry. // // 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(); 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 ("Product 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(); // 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() { //---------------------------------------- // 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 REPRESENTATION // // A product may have 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) //---------------------------------------- // Create the shape representation. In other APs, this would be // the container that holds geometry items. // 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; sdr-> definition (pnew stp_represented_definition); sdr-> definition ()-> _property_definition (pds); sdr-> used_representation (rep); //---------------------------------------- // INITIALIZE THE 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 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); // 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. // stp_cartesian_point* p1 = pnew stp_cartesian_point; p1-> name(""); p1-> coordinates()->add(1.1); p1-> coordinates()->add(2.2); p1-> coordinates()->add(3.3); stp_axis2_placement_3d* ap3d = pnew stp_axis2_placement_3d ( "orientation", p1, 0, 0 ); // Add it to the representation rep-> items()-> add (ap3d); // Done return rep; }