/* * 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 //---------------------------------------- // ADD SOME PDM ATTRIBUTES // // Attach some person, date and approval information to STEP // data. These PDM attributes are mostly assignments in STEP, which // means there is an applied__assignment that attaches the // date, time, person, approval, etc. The attachment is by a Set of // _item, which is an EXPRESS select type that can hold one // of the dozen or so types that can have the attribute. stp_applied_person_and_organization_assignment * assign_person_org( RoseObject * target, stp_person * pers, stp_organization * org, const char * rolename ); stp_applied_approval_assignment * assign_approval( RoseObject * target, stp_person * sign_pers, stp_organization * sign_org, stp_date * sign_date, const char * levname, const char * statname ); stp_applied_date_assignment * assign_date( RoseObject * target, stp_date * date, const char * rolename ); stp_date * make_date(RoseDesign * d); int main(int /*argc*/, char** /*argv*/) { stplib_init(); // initialize STEP class library // Read a file, add some attributes and write back out const char * input_name = "block_and_hole.stp"; const char * output_name = "output_file.stp"; RoseDesign * d = ROSE.findDesign (input_name); if (!d) { printf ("ERROR: Could not read input file!\n"); exit(1); } // Find the first product definition. If it is an assembly there // may be more than one. Look at the WALK_ASSEMBLY sample program // to see how to find your way around a STEP assembly tree. RoseCursor objs; stp_product_definition * pd; objs.traverse(d); objs.domain(ROSE_DOMAIN(stp_product_definition)); pd = ROSE_CAST(stp_product_definition,objs.next()); if (!pd) { printf ("ERROR: Could not find product information!\n"); exit(1); } if (objs.size() > 1) { printf ("WARNING: File contains more than one product!\n"); } // Create a person and company description. The person definition // also has optional middle names, prefix, and suffix titles. // stp_person* pers = pnewIn(d) stp_person(); pers->id("12345-67890"); pers->first_name("Tom"); pers->last_name("Jones"); // The organization. stp_organization* org = pnewIn(d) stp_organization(); org->name("Robot Fish, Inc."); org->description("A fictional company that makes giant robot fish."); // Make a STEP object for today's date stp_date * today = make_date(d); //---------------------------------------- // Attach the PDM attributes to the product or version (product // definition formation. // apply an owner to the product assign_person_org(pd-> formation()->of_product(), pers, org, "id owner"); // apply an approval to the product version assign_approval(pd-> formation(), pers, org, today, "planning", "approved"); // attach a release date to the product version assign_date (pd-> formation(), today, "release date"); // Save to a different file name d-> saveAs(output_name); return 0; } stp_applied_person_and_organization_assignment * assign_person_org( RoseObject * target, stp_person * pers, stp_organization * org, const char * rolename ) { // Pass in the target as a general RoseObject pointer because we // might assign a person+org to a product, approval, formation, // product_definition, or any of the two dozen other things that // it could be attached to. RoseDesign * d = target->design(); // Relate the person to the organization. stp_person_and_organization* pao = pnewIn(d) stp_person_and_organization(); pao->the_person(pers); pao->the_organization(org); // Set the role of the assignment to be design_owner. The role // and the instances in the items list much match. See function // cc_design_person_and_organization_correlation and rule // restrict_person_organization_role in AP-203 for more // information. stp_person_and_organization_role* paor = pnewIn(d) stp_person_and_organization_role(); paor->name(rolename); // Create an assignment object to relate the person to the product // with a partular role. stp_applied_person_and_organization_assignment * assign = pnewIn(d) stp_applied_person_and_organization_assignment(); assign->role(paor); assign->assigned_person_and_organization(pao); // Items is a set of item select instances. assign->items(pnewIn(d) SetOfstp_person_and_organization_item()); // The person_organization_item is an EXPRESS select (like a // union) that can hold one of any of the different types of // objects that a person/org can be assigned to. // stp_person_and_organization_item * poi = pnewIn(d) stp_person_and_organization_item(); assign->items()->add(poi); rose_put_nested_object(poi, target); // return the assignment object in case you want to do anything // else with it. return assign; } stp_applied_approval_assignment * assign_approval( RoseObject * target, stp_person * sign_pers, stp_organization * sign_org, stp_date * sign_date, const char * levname, const char * statname ) { RoseDesign * d = target->design(); // Create the approval root object and assign a level - AP214 // expects the level to be "disposition" "equipment order" or // "planning" AP203 never had any standard mapping for this. stp_approval * app = pnewIn(d) stp_approval(); app->level(levname); // assign an approval status - this is restricted to approved, // not_yet_approved, disapproved, or withdrawn by a rule in AP203. stp_approval_status * app_stat = pnewIn(d) stp_approval_status(); app_stat->name(statname); app->status(app_stat); // Create the approval assignment entity. And initialize the items list. stp_applied_approval_assignment * assign = pnewIn(d) stp_applied_approval_assignment(); assign->assigned_approval(app); assign->items(pnewIn(d) SetOfstp_approval_item()); // Create an approval_item to hold the thing we are approving and // add to the approved items list. As with assign_person_org() we // just use a RoseObject* since there are so many different things // that we could attach an approval to. stp_approval_item* ai = pnewIn(d) stp_approval_item(); assign->items()->add(ai); rose_put_nested_object(ai, target); // The approval requires an approval_person_organization instance // to identify the person responsible for approving the various // items. Note that the person_organization field is a select. stp_approval_person_organization* app_po = pnewIn(d) stp_approval_person_organization(); app_po->authorized_approval(app); app_po->person_organization(pnewIn(d) stp_person_organization_select()); // attach the sign off date or the approval_person_organization assign_date (app_po, sign_date, "sign off"); // You can have an person, organization, or both so check to see // if the caller passed in null of anything if (sign_pers && sign_date) { stp_person_and_organization* pao = pnewIn(d) stp_person_and_organization(); pao->the_person(sign_pers); pao->the_organization(sign_org); app_po->person_organization()->_person_and_organization(pao); } else if (sign_pers) { app_po->person_organization()->_person(sign_pers); } else if (sign_org) { app_po->person_organization()->_organization(sign_org); } // The approval_person_organization has a role which can be used to // specify different roles in the approval process. If there is no // special role, approver is recommended. stp_approval_role* app_role = pnewIn(d) stp_approval_role(); app_role->role("approver"); app_po->role(app_role); return assign; } stp_applied_date_assignment * assign_date( RoseObject * target, stp_date * date, const char * rolename ) { RoseDesign * d = target->design(); // The approval_person_organization should have a // cc_design_date_and_time_assignment to signify when the person // acted in the role specified by the approval_person_organization // on a particular date. Here we're reusing the date with the role // of sign_off_date. stp_applied_date_assignment * assign = pnewIn(d) stp_applied_date_assignment(); assign->assigned_date(date); assign->role (pnewIn(d) stp_date_role); assign->role()->name(rolename); // Pass in the target as a RoseObject* since there are so many // different things that we could attach a date to. stp_date_item * dti = pnewIn(d) stp_date_item(); rose_put_nested_object(dti, target); assign->items (pnewIn(d) SetOfstp_date_item()); assign->items()->add(dti); return assign; } stp_date * make_date(RoseDesign * d) { // Get current time, decode and create a STEP calendar_date time_t nowtime; if ( (nowtime = time(0)) == -1) return 0; struct tm * time_struct = localtime (&nowtime); stp_calendar_date* date = pnewIn(d) stp_calendar_date(); date->year_component (1900 + time_struct->tm_year); /* year since 1900 */ date->month_component (time_struct->tm_mon+1); /* month is 0-11 */ date->day_component (time_struct->tm_mday); return date; }