/* $RCSfile.cxx,v $ * $Revision: 1.6 $ $Date: 2007/08/29 21:48:35 $ * Auth: Blair Downie (downie@steptools.com) * 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 // The ASSEMBLY sample program demonstrates how to construct an assembly // between two products. An assembly relationship is constructed to // relate the configuration management instances as well as the geometry. // The program is broken down into functions which handle portions of the // complete relationship. The input file for the program must contain at // least two products with geometry. // // The program reads the "assembly_in.stp" data set and saves two // different versions of it called "output_with_mapped_item.stp" and // "output_with_cdsr.stp". STEP files are text, so you can look at // them with a text editor or right-click "Browse" them with the STEP // Part 21 file browser to see the contents. // STEP ASSEMBLIES -- STEP assembly relationships are constructed on // two levels, relating the configuration management instances and // another relating the geometry. // // Instances of shape_definition_representation (SDR) join the // configuration management data and the geometry. // // For demo purposes, The create_demo_assembly function traverses the // SDRs and uses the first one seen as the assembly and the second as // the component. An actual program would have some other method of // selecting or creating the assembly and the component. // // The program then navigates from the SDRs to the product_definitions // so that it can make the assembly relationship at the cm level using // product_definition_relationship subtypes called next_assembly_usage_ // occurrence. Then the program creates some default transformation // information and builds the geometric relationship. // void create_demo_assembly ( int useMappedItem ); // Given two product_definitions this creates an assembly between them. stp_next_assembly_usage_occurrence* createCMAsm( const char* asm_id, const char* asm_usage, const char* asm_desc, const char* ref_desig, stp_product_definition* asm_pdef, stp_product_definition* comp_pdef ); // Used for relating two shape_representations of the same type. // Given two shape_representations and their axis2_placements, this // creates the geometric portion of the assembly using a mapped_item. void createGeomAsmMI( stp_representation* asmSR, stp_representation_item* asmAxis, stp_representation* compSR, stp_representation_item* compAxis, stp_next_assembly_usage_occurrence* nauo ); // Used for relating two shape_representations of different types. // Given two shape_reps and their axis2_placements, this creates the // geometric portion of the assembly using a // context_dependent_shape_representation. void createGeomAsmCDSR( stp_representation* asmSR, stp_representation_item* asmAxis, stp_representation* compSR, stp_representation_item* compAxis, stp_next_assembly_usage_occurrence* nauo ); // Find the product_definition that a property is attached to. Note // that properties can be attached to other things besides a product // definition. // stp_product_definition * get_property_pdef ( stp_property_definition_representation * pdr ); // Given a product_definition for an assembly, try to find the // security classification that goes along with it. This is an // AP203-specific thing. Other APs like AP214 generally do not // require a security classification. // stp_cc_design_security_classification* getClassification( stp_product_definition* asmDef ); 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 const char * input_name = "assembly_in"; const char * mi_output_name = "output_with_mapped_item"; const char * csdr_output_name = "output_with_cdsr"; RoseDesign * design; // Demonstrate two styles of assembly // Read the design, create the mapped item version of an assembly, // and save. Then delete the design, read a fresh copy and create // the context-dependent shape rep version. // Uncomment the format() 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 = ROSE.useDesign (input_name); create_demo_assembly (1); /* relate as mapped item */ // design-> format ("p28"); design-> saveAs (mi_output_name); // delete the design so we can read a fresh copy rose_move_to_trash (design); rose_empty_trash(); // Read it in again, and create the other style of assembly design = ROSE.useDesign (input_name); create_demo_assembly (0); /* relate as CSDR */ // design-> format ("p28"); design-> saveAs (csdr_output_name); return 0; } // This function picks the first two products with geometry and builds // an assembly between them. In practice, you would get the relevant // products and related geometric offsets from user interaction or // some other part of your application // void create_demo_assembly (int useMappedItem) { // find the two shape_defintion_representations. For this // example, we just pick the first two, presumably there's some // way to select the part and assembly. // RoseCursor cursor; cursor.traverse (ROSE.design()); cursor.domain (ROSE_DOMAIN(stp_shape_definition_representation)); stp_shape_definition_representation* asm_sdr = ROSE_CAST(stp_shape_definition_representation, cursor.next()); stp_shape_definition_representation* comp_sdr = ROSE_CAST(stp_shape_definition_representation, cursor.next()); // RELATE THE PRODUCT STRUCTURE -------------------- // Find the product definitions by following the definition // attribute of the shape definition representations. stp_product_definition * asm_pd = get_property_pdef (asm_sdr); stp_product_definition * comp_pd = get_property_pdef (comp_sdr); // Create the association between the configuration management // description of the assembly and component. // stp_next_assembly_usage_occurrence* nauo = createCMAsm( "unique ID", // any unique id string "left tire", // something that identifies the usage. "", // description, "" is fine. 0, // Optional reference_designator string used // to separate multiple uses of a component. asm_pd, comp_pd ); // RELATE THE GEOMETRY -------------------- // We need locations for the assembly and the component, so we // create some example axis2_placements // stp_cartesian_point* p1 = pnew stp_cartesian_point; p1-> name(""); p1-> coordinates()->add(0); p1-> coordinates()->add(0); p1-> coordinates()->add(0); stp_axis2_placement_3d* asmAxis = pnew stp_axis2_placement_3d("", p1, 0, 0); stp_cartesian_point* p2 = pnew stp_cartesian_point; p2-> name(""); p2-> coordinates()->add(0); p2-> coordinates()->add(0); p2-> coordinates()->add(0); stp_axis2_placement_3d* compAxis = pnew stp_axis2_placement_3d("", p2, 0, 0); // Create the association between the geometry description of the // assembly and component. There are two distinct ways to relate // the geometry. // if (useMappedItem) { createGeomAsmMI( asm_sdr->used_representation(), asmAxis, comp_sdr->used_representation(), compAxis, nauo); } else { createGeomAsmCDSR( asm_sdr->used_representation(), asmAxis, comp_sdr->used_representation(), compAxis, nauo); } } // Given two product_definitions this creates an assembly between them. stp_next_assembly_usage_occurrence* createCMAsm( const char* asm_id, const char* asm_usage, const char* asm_desc, const char* ref_desig, stp_product_definition* asm_pdef, stp_product_definition* comp_pdef ) { // Create a next_assembly_usage occurrence to link the two. stp_next_assembly_usage_occurrence* nauo = pnew stp_next_assembly_usage_occurrence(); // The id has no standard mapping, but it should be unique. nauo->id (asm_id); // The name should contain something that identifies the usage. nauo->name (asm_usage); // There's no mapping for the description, "" is fine.. nauo->description (asm_desc); // The reference_designator is optional. When specified, it // should contain a unique location for the assembly. nauo->reference_designator (ref_desig); // The relating_product_definition is the assembly. nauo->relating_product_definition (asm_pdef); // The related_product_definition is the component. nauo->related_product_definition (comp_pdef); // In AP203, all assembly component usages (like the NAUO) require // a security classification. This is specific to AP203 and does // not show up in AP214 // stp_cc_design_security_classification* sec = getClassification(asm_pdef); stp_classified_item* ci = pnew stp_classified_item(); ci->_assembly_component_usage(nauo); sec->items()->add(ci); return nauo; } // This approach can be used if both of the shape descriptions are the // same type (same shape rep subtype). Given two shape_representations // and their axis2_placements, this creates the geometric portion of // the assembly using a mapped_item. // void createGeomAsmMI( stp_representation* asmSR, stp_representation_item* asmAxis, stp_representation* compSR, stp_representation_item* compAxis, stp_next_assembly_usage_occurrence* nauo ) { /* We pass in representations to avoid having to do casts, * but this should only be used to relate instances of the * shape representation subtype. */ if (!asmSR-> isa (ROSE_DOMAIN(stp_shape_representation)) || !compSR-> isa (ROSE_DOMAIN(stp_shape_representation))) { printf ("createGeomAsmMI: representations must be instances of"); printf (" the shape representation subtype"); return; } // Create a mapped item & representation map for the component. stp_mapped_item* mi = pnew stp_mapped_item(); stp_representation_map* rm = pnew stp_representation_map(); // The name of the mapped item has no standard mapping. mi->name(""); // The source of the mapped_item is the representation_map. mi->mapping_source(rm); // The target is the assembly's axis. mi->mapping_target(asmAxis); // The mapping origin is the components coordinate system. rm->mapping_origin(compAxis); // The mapped_representation is the component shape_representation. rm->mapped_representation(compSR); // Now a new shape_representation is needed for the // next_assembly_usage_occurrence. This shape_representation will // reference the mapped_item used in this assembly so that one can // navigate from the nauo to the mapped_item. This is important // because a component can be referenced more than once in an // assembly (left tire, right tire) and this way the // correspondence between the nauo and mapped_item for each // instance can be maintained. Create the same kind of shape_rep // as the others. stp_shape_representation* nauoSR = ROSE_CAST(stp_shape_representation, asmSR->domain()->pnewInstance()); // There's no mapping for the representation name. nauoSR->name(""); // We'll reuse the context from the assembly. nauoSR->context_of_items(asmSR->context_of_items()); // Create a new items list. SetOfstp_representation_item* items = pnew SetOfstp_representation_item(); nauoSR->items(items); // Reference the mapped_item. items->add(mi); // now attach the shape_representation to the nauo using a // product_definition_shape and a shape_definition_representation. stp_product_definition_shape* pds = pnew stp_product_definition_shape(); stp_shape_definition_representation* sdr = pnew stp_shape_definition_representation(); // There's no standard mapping for the name or description. pds->name(""); pds->description(""); // The definition should point to next_assembly_usage_occurrence. stp_characterized_definition* cd = pnew stp_characterized_definition(); stp_characterized_product_definition* cpd = pnew stp_characterized_product_definition(); cd->_characterized_product_definition(cpd); cpd->_product_definition_relationship(nauo); pds->definition(cd); // The definition of the shape_definition_representation is the // product_definition_shape. APs based on the first edition of // the integrated resources (203/202) have a direct pointer to the // PDS, but in more recent APs the reference goes through a select // type called represented_definition. It looks the same in the // P21 file. // sdr-> definition (pds); // The representation is the new one we've created. sdr->used_representation(nauoSR); } // This method should be used if the shape types are different. Given // two shape_representations and their axis2_placements, this creates // the geometric portion of the assembly using a // context_dependent_shape_representation. // void createGeomAsmCDSR( stp_representation* asmSR, stp_representation_item* asmAxis, stp_representation* compSR, stp_representation_item* compAxis, stp_next_assembly_usage_occurrence* nauo ) { /* We pass in representations to avoid having to do casts, * but this should only be used to relate instances of the * shape representation subtype. */ if (!asmSR-> isa (ROSE_DOMAIN(stp_shape_representation)) || !compSR-> isa (ROSE_DOMAIN(stp_shape_representation))) { printf ("createGeomAsmCDSR: representations must be instances of"); printf (" the shape representation subtype"); return; } // Create a product_definition_shape to link the cdsr to the nauo stp_product_definition_shape* pds = pnew stp_product_definition_shape(); // There's no standard mapping for the name or description. pds->name(""); pds->description(""); // The definition should point to next_assembly_usage_occurrence. stp_characterized_definition* cd = pnew stp_characterized_definition(); stp_characterized_product_definition* cpd = pnew stp_characterized_product_definition(); cd->_characterized_product_definition(cpd); cpd->_product_definition_relationship(nauo); pds->definition(cd); // Create a context_dependent_shape_representation. stp_context_dependent_shape_representation* cdsr = pnew stp_context_dependent_shape_representation(); // The represented_product_relation is the pds. cdsr->represented_product_relation(pds); // A complex entity is used for the shape_representation_relationship. stp_representation_relationship_with_transformation_and_shape_representation_relationship * repRel = pnew stp_representation_relationship_with_transformation_and_shape_representation_relationship(); cdsr->representation_relation(repRel); // The name and description attributes have no standard mapping repRel->name(""); repRel->description(""); // rep_1 is the assembly shape and rep_2 is the component. repRel->rep_1(asmSR); repRel->rep_2(compSR); // The transformation_operator should be an item_defined_transform. stp_item_defined_transformation* xform = pnew stp_item_defined_transformation(); stp_transformation* trans = pnew stp_transformation(); trans->_item_defined_transformation(xform); repRel->transformation_operator(trans); // The name and description fields have no standard mapping. xform->name(""); xform->description(""); // The first transform_item is the axis of the assembly and the second is // the component. xform->transform_item_1(asmAxis); xform->transform_item_2(compAxis); } stp_product_definition * get_property_pdef ( stp_property_definition_representation * pdr ) { /* Find the product_definition that a property is attached to. * Note that properties can be attached to other things besides a * product definition. This also works on property definition * representation subtypes like shape_definition_representation. */ /* The pd_representation has a definition that refers to a * property_definition. In AP-203 this is a direct reference, * but in other APs it goes through a represented_definition * select type. */ if (!pdr->definition()) return 0; /* The property_definition has a definition that usually refers to * a product_definition, but could refer to other things. The link * to product_definition goes through another select type called * characterized_product_definition, so we have to look down two * levels. Refer to the HTML version of the EXPRESS schema for a * better picture of how these are nested. */ stp_property_definition * prop = pdr->definition(); stp_characterized_definition * cd = prop-> definition(); if (cd-> is_characterized_product_definition()) { stp_characterized_product_definition * cpd = cd-> _characterized_product_definition(); if (cpd-> is_product_definition()) return cpd-> _product_definition(); } return 0; } // Given a product_definition for an assembly, try to find the // security classification that goes along with it. This is an // AP203-specific thing. Other APs like AP214 generally do not // require a security classification. // stp_cc_design_security_classification* getClassification( stp_product_definition* asmDef ) { // On this example we just use the classification for the product // definition formation of the assembly product definition. // stp_product_definition_formation* formation = asmDef->formation(); // Use the RoseObject usedin() functionality to search through the // file for a security classification that references the PDF // RoseAggregate* agg = formation-> usedin( ROSE_DOMAIN(stp_cc_design_security_classification),0,0 ); // If there are any, just pick the first one. if (agg->size() > 0) { return ROSE_CAST(stp_cc_design_security_classification, agg->getObject((unsigned) 0)); } // Otherwise create a new classification - ap203_cc1 sample // program for a complete example. stp_cc_design_security_classification* sec = pnew stp_cc_design_security_classification(); sec->items(pnew SetOfstp_classified_item()); // This also requires a classification officer and date, but you // that is left as an exercise ... return sec; }