int run() { /* Force optimizing linkers to bring in all C++ classes */ stplib_init(); /* Create a RoseDesign to hold the instance data */ const char * output_name = "cylinder"; RoseDesign * design = new RoseDesign(output_name); /* Give the design some Part 21 header information */ design->initialize_header(); design->header_name()->originating_system("Cylinder Creation"); design->header_description()->description()-> add("Empty Shape Representation Sample File"); ROSE.useDesign(design); StixUnit au = stixunit_deg; StixUnit lu = stixunit_mm; StixUnit sau = stixunit_steradian; stp_advanced_brep_shape_representation * cylin = create_empty_product_with_geometry_cylinder( au, lu, sau); const char* c = "red"; create_any_cylinder(cylin, 5, 10, 2.5, 2.5, 5, c); design->save(); return 0; }
void _tmain(int argc, _TCHAR* argv[]) { bool isOpen = GetStepFileDialog(); if(!isOpen) { printf("打开文件错误!\n"); exit(1); } ROSE.quiet(1); // console show; stplib_init(); // initialize merged cad library stixmesh_init(); RoseDesign* design = ROSE.findDesign(pathName.c_str()); //RoseDesign* design = ROSE.findDesign("11.STEP"); if (!design) { printf("Could not open STEP file %s\n", pathName.c_str()); exit(1); } rose_compute_backptrs(design); stix_tag_asms(design); Partition* part = new Partition(design); }
int main(int argc, char* argv[]) { /* Force optimizing linkers to bring in all C++ classes */ stplib_init(); /* Create a RoseDesign to hold the instance data */ const char * output_name = "cylinder_with_filet"; RoseDesign * design = new RoseDesign(output_name); /* Give the design some Part 21 header information */ design->initialize_header(); design->header_name()->originating_system("Cylinder Creation"); design->header_description()->description()-> add("Empty Shape Representation Sample File"); ROSE.useDesign(design); stp_advanced_brep_shape_representation * cylin = create_empty_product_with_geometry(); create_any_cylinder(cylin, 8, 10, 4); design->save(); return 0; }
int main(int argc, char* argv[]) { ROSE.quiet(1); //Get rid of annoying ST-Dev output. stplib_init(); // initialize merged cad library FILE *out; out = fopen("log.txt", "w"); ROSE.error_reporter()->error_file(out); RoseP21Writer::max_spec_version(PART21_ED3); //We need to use Part21 Edition 3 otherwise references won't be handled properly. RoseP21Writer::preserve_eids=ROSE_TRUE; RoseDesign * testAnchorAndData = ROSE.newDesign("testAnchorAndData"); stplib_put_schema(testAnchorAndData, stplib_schema_ap214); stp_cartesian_point *point =pnew stp_cartesian_point; point->entity_id(321); //Make the entity ID something we can check later. point->name("TestPoint"); point->coordinates()->add(1.01); point->coordinates()->add(2.01); point->coordinates()->add(3.01); testAnchorAndData->addName("TestAnchor", point); testAnchorAndData->save(); RoseDesign * testRefAndAnchor = ROSE.newDesign("testRefAndAnchor"); stplib_put_schema(testRefAndAnchor, stplib_schema_ap214); auto ref = rose_make_ref(testRefAndAnchor, "testAnchorAndData.stp#TestAnchor"); //Manually make the reference point to the other file. ref->entity_id(123); //Just give it an entity id so we can check it later. testRefAndAnchor->addName("ParentAnchor", ref); //Add an anchor which points to the reference. stp_circular_area *area = pnew stp_circular_area; //Make something to test if the reference resolves properly area->name("testarea"); area->radius(2.0); rose_put_ref(ref, area, "centre"); testRefAndAnchor->save(); //Okay, so now we have two files- one with an anchor pointing to a reference, and one with an anchor and the data the anchor points to. Lets see what the anchor in the higher file points to. std::cout << "Anchor " << testRefAndAnchor->nameTable()->listOfKeys()->get(0) <<" points to (should be 123): " <<testRefAndAnchor->nameTable()->listOfValues()->get(0)->entity_id() <<'\n'; //That should output "Anchor ParentAnchor points to: 123" //Now lets merge. //First things first, we close the child design just to be certain we are doing it EXACTLY LIKE MERGE. rose_move_to_trash(testAnchorAndData); testRefAndAnchor->saveAs("testmerge.stp"); rose_move_to_trash(testRefAndAnchor); rose_empty_trash(); //now all of this is out of memory. RoseDesign *parent = ROSE.findDesign("testmerge.stp"); //Open the new file. Don't mess with the files we created earlier. if (!parent) { std::cout << "Shit's f****d\n"; return EXIT_FAILURE; } //Call the URI parser function. RoseCursor * cursor = new RoseCursor; cursor->traverse(parent->reference_section()); cursor->domain(ROSE_DOMAIN(RoseReference));//Go through all the references in parent. All one of them. std::cout << "Cursor size (should be 1): " << cursor->size() <<'\n'; RoseObject * obj = cursor->next(); std::cout << "Reference ID (should be 123): " << obj->entity_id() << '\n'; ref = ROSE_CAST(RoseReference, obj); //Now we have the reference as an actual Reference object instead of a generic RoseObject. std::string file, anchor,dir="./"; URIParse(ref->uri(), file, anchor,dir); std::cout << "file (should be testAnchorAndData.stp): " << file << "\nanchor (should be TestAnchor): " << anchor << "\ndir (should be ./): " << dir << '\n'; std::cout << "Anchor " << parent->nameTable()->listOfKeys()->get(0) << " points to (should be 123): " << parent->nameTable()->listOfValues()->get(0)->entity_id() << '\n'; RoseDesign *child = ROSE.findDesign(file.substr(0, file.find('.')).c_str()); if (!child) { std::cout << "Shit's f****d\n"; return EXIT_FAILURE; } std::cout << "Anchor " << parent->nameTable()->listOfKeys()->get(0) << " points to (should be 123): " << parent->nameTable()->listOfValues()->get(0)->entity_id() << '\n'; obj = child->findObject(anchor.c_str()); //Get the object associated with the anchor std::cout << "Child Object Pointed to by Anchor Entity ID (should be 321): " << obj->entity_id() <<'\n'; obj->move(parent); //move object to parent so we have it in the right place, then resolve references. RoseRefUsage *rru = ref->usage(); //rru is a linked list of all the objects that use ref do { std::cout << "Resolving reference in entity ID: " << rru->user()->entity_id() <<'\n'; int rrureturn = ResolveRRU(rru,obj); if (-1 == rrureturn) break; } while (rru = rru->next_for_ref()); //Do this for anything that uses the reference. //parent->save(); //At this point, the data section references are resolved. You can check the output file if you want to be sure. Just uncomment that save. //Now resolve the reference in the anchor section. DictionaryOfRoseObject * anchors = parent->nameTable(); for (unsigned i = 0, sz = anchors->size(); i < sz; i++) { if (anchors->listOfValues()->get(i) == ref) { std::cout << "anchor " << anchors->listOfKeys()->get(i) << " has an entity ID of (should be 123): " << anchors->listOfValues()->get(i)->entity_id() <<'\n'; anchors->add(anchors->listOfKeys()->get(i), obj); std::cout << "anchor " << anchors->listOfKeys()->get(i) << " has an entity ID of (should be 321): " << anchors->listOfValues()->get(i)->entity_id() << '\n'; } } parent->save(); return EXIT_SUCCESS; }