/* * 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 #include #include #include "geometry_utils.h" #include "unit_utils.h" // BUILD GEOMETRY - This is a CIS/2 "hello world" program that creates // a building with shape and attaches some unit contexts. Use this as // the starting point for a more sophisticated program. // 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. shape_representation * create_building_with_geometry(); int main(int argc, char* argv[]) { /* Force optimizing linkers to bring in all C++ classes */ structural_frame_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 ("CIS/2 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_building_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; } shape_representation * create_building_with_geometry() { //---------------------------------------- // CREATE THE BUILDING - // Create a building with shape object, and fill it in with some // sample information // building_with_shape * b = pnew building_with_shape(); b-> item_number (1); b-> item_name ("fortress of solitude"); b-> building_class ("secret lair"); // Create the shape representation. This is the container that // holds geometry items. CIS/2 has a special with_units subtype // for when this is associated with units in a context. // shape_representation_with_units * rep = pnew shape_representation_with_units; b-> shape (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. // // Note that CIS/2 handles non SI units differently than STEP. // 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_foot_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. // cartesian_point* p1 = pnew cartesian_point; p1-> name(""); p1-> coordinates()->add(1.1); p1-> coordinates()->add(2.2); p1-> coordinates()->add(3.3); axis2_placement_3d* ap3d = pnew axis2_placement_3d ( "orientation", p1, 0, 0 ); // Add it to the representation rep-> items()-> add (ap3d); // Done return rep; }