/* * 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: Charles Gilman (gilman@steptools.com) * Author: Dave Loffredo (loffredo@steptools.com) */ #include #include #include #include "context_utils.h" #include "unit_utils.h" // The PROPERTY sample program demonstrates how to attach properties // to a product. This program builds all of the STEP backbone entities // that go into creating a product and two sample properties. We // create a string descriptive propery and one that has a length // measure. // 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. void create_sample_property(); void attach_property_value ( stp_product_definition * pd, const char * prop_name, stp_representation_item * rep_item ); int main(int /*argc*/, char** /*argv*/) { stplib_init(); // initialize STEP class library 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); // Declare it as an AP214 file stplib_put_schema (design, stplib_schema_ap214); // Give the design some Part 21 header information design-> initialize_header(); design-> header_name()-> originating_system ("Property Demo"); design-> header_description()-> description ()-> add ("Property 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_sample_property(); // 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; } void create_sample_property() { //---------------------------------------- // CREATE A SAMPLE PRODUCT - // Create a product and associated step backbone objects that // we will attach our property to. // // The frame of reference context information is boilerplate, // see context_utils.cxx for the specifics. // 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"); 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. // The frame of reference context information is boilerplate, // see context_utils.cxx for the specifics. // stp_product_definition* pd = pnew stp_product_definition(); pd-> formation (pdf); pd-> id ("design"); pd-> description ("example product_definition"); pd-> frame_of_reference (make_pdef_context()); //---------------------------------------- // FIRST PROPERTY EXAMPLE // // Create a paramater called overall_shape with a value of tubular. // // Create the value of 'tubular'. The property value is held in a // representation, so we must use a subtype of representation_item // to hold the value. The descriptive_representation_item holds // string value types. stp_descriptive_representation_item * dri = pnew stp_descriptive_representation_item; dri-> name("id001"); dri-> description("tubular"); // Now link the property to the product definition attach_property_value (pd, "overall_shape", dri); //---------------------------------------- // SECOND PROPERTY EXAMPLE // // Create a parameter called coating thickness with a value // of 0.5mm // // Create the value of '0.5mm'. The property value is held in a // representation, so we must use a subtype of representation_item // to hold the value. The measure_representation_item holds types // of things that are measured quantities. // // For length measurements, there is a subtype that inherits from // both measure_rep_item and length_measure_with_unit that we use. // It is a one of the AND/OR Complex types that express supports, // and the C++ class inherits from both types with a name made by // concatenating both with '_and_' // // There is a similar special type for plane_angle_measures // stp_length_measure_with_unit_and_measure_representation_item * mwu = pnew stp_length_measure_with_unit_and_measure_representation_item; // Fill in the numeric value 0.5, and the unit value of mm. See // the file unit_utils.cxx for more specifics on how units are put // together in STEP. // mwu-> name ("len001"); mwu-> value_component (pnew stp_measure_value); mwu-> value_component ()-> _length_measure (0.5); mwu-> unit_component (pnew stp_unit); mwu-> unit_component ()-> _named_unit (make_mm_unit()); // Now link the property to the product definition attach_property_value (pd, "coating thickness", mwu); } void attach_property_value ( stp_product_definition * pd, const char * prop_name, stp_representation_item * rep_item ) { // In STEP, properties are attached to something through 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 a property_definition for the property and set the name // and definition attributes. The name attribute holds the name of // the property. // stp_property_definition * prop = pnew stp_property_definition; prop-> name (prop_name); prop-> description (""); // The product definition is held by a nested select type. A // characterized_definition, characterized_product_definition, // and then the product_definition // prop-> definition (pnew stp_characterized_definition); prop-> definition()-> _characterized_product_definition (pnew stp_characterized_product_definition); prop-> definition()-> _characterized_product_definition()-> _product_definition (pd); // Create the representation and add our rep item. Depending on // the type of property, you may need to create a representation // subtype. Normally this is spelled out in the AP constraints // and mapping table. // stp_representation * rep = pnew stp_representation; rep-> name(""); rep-> items()-> add (rep_item); // The representation needs a context. For geometry, the context // gives the units and number of dimensions (2D/3D). Our propery // is self describing (the measure already has a unit) so we do // not need any other context information. Just create a default // context. // // In a real application, we would only create one for our entire // file, but here we just create one each time stp_representation_context * ctx = pnew stp_representation_context; ctx-> context_identifier ("default"); ctx-> context_type ("default"); rep-> context_of_items (ctx); // Attach the representation to the property_definition using a // property_definition_representation. Note that the pdr refers // to the property definition through a represented_definition // select type. // stp_property_definition_representation * pdr = pnew stp_property_definition_representation; pdr-> used_representation (rep); pdr-> definition (pnew stp_represented_definition); pdr-> definition()-> _property_definition (prop); }