/* * 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: Jochen Fritz (jfritz@steptools.com) */ #include #include static void dump_product_tree (stp_product_definition * pd, unsigned depth=0); static void dump_asm_tree (stp_product_definition * pd); static void dump_shape_rep(stp_representation * sr, unsigned depth=0); static void dump_child_rel(RoseObject * rel, unsigned depth=0); static char * get_product_name (stp_product_definition * pdef); int main(int /*argc*/, char** /*argv*/) { stplib_init(); // initialize STEP class library const char * input_name = "walkasm_in.stp"; RoseDesign * d = ROSE.findDesign (input_name); if (!d) { printf ("Could not open design %s\n", input_name); exit (1); } // This code traverses the STEP data and annotates the products, // shape reps and relationship objects with manager objects that // hold backpointer data that makes it easier to navigate the // assembly structure. stix_tag_asms (d); // Now navigate through the assembly, starting with the root // products, and print the product structue and the shape rep // structure. unsigned i,sz; StpAsmProductDefVec roots; stix_find_root_products (&roots, d); printf ("\nPRODUCT TREE ====================\n"); for (i=0, sz=roots.size(); i formation(): 0; stp_product * p = pdf? pdf-> of_product(): 0; return p? p-> name(): 0; } void indent (unsigned d) { while (d--) printf (" "); } void dump_product_tree (stp_product_definition * pd, unsigned depth) { unsigned i,sz; StixMgrAsmProduct * pm = StixMgrAsmProduct::find(pd); char * nm = get_product_name(pd); indent(depth); printf ("Product: #%lu '%s' %s %s\n", pd->entity_id(), nm? nm: "", pm->has_parent ? "(child)" : "(root)", pm->has_orphan_shapes ? "(orphan shapes)" : "" ); indent(depth+1); printf ("shape count: %d\n", pm->shapes.size()); for (i=0, sz=pm->shapes.size(); ishapes[i]; indent(depth+1); printf ("shape_rep[%d] = #%lu\n", i, sr->entity_id()); } for (i=0, sz=pm->child_nauos.size(); ichild_nauos[i]); indent(depth+1); printf ("NAUO = #%lu -> #%lu\n", pm->child_nauos[i]->entity_id(), rel->entity_id() ); dump_product_tree(rel, depth+1); } } void dump_asm_tree(stp_product_definition * pd) { unsigned i, sz; StixMgrAsmProduct * pm = StixMgrAsmProduct::find(pd); printf ("Assembly tree rooted at product #%lu\n", pd->entity_id()); for (i=0, sz=pm->shapes.size(); ishapes[i]); } } void dump_shape_rep(stp_representation * sr, unsigned depth) { unsigned i,sz; StixMgrAsmShapeRep * mgr = StixMgrAsmShapeRep::find(sr); /* Shape rep was not resolved */ if (!mgr) return; indent(depth); printf ("Shape rep #%lu\n", sr->entity_id()); if (mgr->root_placement && depth==0) { indent(depth+1); printf ("Root placement #%lu\n", mgr->root_placement->entity_id()); } for (i=0, sz=mgr->products.size(); iproducts[i]->entity_id()); } for (i=0, sz=mgr->child_rels.size(); ichild_rels[i]; indent(depth+1); printf ("Representation relationship: #%lu",rel->entity_id()); if (rel->isa(ROSE_DOMAIN (stp_representation_relationship_with_transformation))) { stp_representation_relationship_with_transformation * rrt = ROSE_CAST(stp_representation_relationship_with_transformation, rel); RoseObject * trans_op = rose_get_nested_object ( rrt-> transformation_operator() ); if (trans_op && trans_op->isa(ROSE_DOMAIN(stp_item_defined_transformation))) { stp_item_defined_transformation * idt = ROSE_CAST(stp_item_defined_transformation, trans_op); printf (" (tranform=#%lu)", idt->entity_id()); } } printf ("\n"); dump_child_rel(rel, depth); } sz = mgr->child_mapped_items.size(); for (i=0; ichild_mapped_items[i]; indent(depth+1); printf ("Mapped item: #%lu\n", mi->entity_id()); dump_child_rel(mi, depth); } } // This code takes a general RoseObject* as input since it can work // with either mapped items and shape rep relationships. We attach a // relation manager to either, so that is what we work with. // void dump_child_rel(RoseObject * rel, unsigned depth) { depth++; StixMgrAsmRelation * mgr = StixMgrAsmRelation::find(rel); indent(depth); printf ("Child rep=#%lu %s\n", mgr->child->entity_id(), mgr->reversed ? "(reversed)" : ""); if (mgr->origin) { indent(depth+1); printf ("origin=#%lu (%s)\n", mgr->origin->entity_id(), mgr->origin->domain()->name() ); } if (mgr->target) { indent(depth+1); printf ("target=#%lu (%s)\n", mgr->target->entity_id(), mgr->target->domain()->name() ); } dump_shape_rep(mgr->child, depth+1); }