Esempio n. 1
0
void Partition::GetSFaceInfo(SetOfstp_face* stpFace)
{
	for(size_t i = 0; i < stpFace->size(); i++)
	{
		stp_face* face = stpFace->get(i);
		stp_advanced_face* adFace = ROSE_CAST(stp_advanced_face, face);
		NatlHalfVector(adFace);
	}
}
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;
}
Esempio n. 3
0
void Partition::NatlHalfVector(stp_advanced_face* adFace)
{
	char* entityName = adFace->face_geometry()->className();

	/*! get bounds to vector<FaceBounds*> faceBounds_ */
	vector<FaceBounds*> faceBounds;
	SetOfstp_face_bound* bounds = adFace->bounds();
	for(size_t i = 0; i < bounds->size(); i++)
	{
		vector<Curve*> curveTemp;
		FaceBounds* faceB = new FaceBounds;

		stp_face_bound* bound = bounds->get(i);
		stp_edge_loop* edgeLoop = ROSE_CAST(stp_edge_loop, bound->bound());
		ListOfstp_oriented_edge* oriList = edgeLoop->edge_list();

		for(size_t j = 0; j < oriList->size(); j++)
		{
			GeometryData tempGepmetry;
			Curve* cur = new Curve;
			stp_oriented_edge* oriEdge = oriList->get(j);
			stp_edge_curve* curve = ROSE_CAST(stp_edge_curve, oriEdge->edge_element());
			stp_curve* pcurve = curve->edge_geometry();//line, circle,ellipse,surface_curve
			if(!strcmp(pcurve->className(), "line"))
			{
				stp_line* line = ROSE_CAST(stp_line, pcurve);
				CPoint3D point(line->pnt()->coordinates()->get(0),
					line->pnt()->coordinates()->get(1),
					line->pnt()->coordinates()->get(2));
				((LINE*)cur)->pnt_ = point;
				CVector3D dir(line->dir()->orientation()->direction_ratios()->get(0),
					line->dir()->orientation()->direction_ratios()->get(1),
					line->dir()->orientation()->direction_ratios()->get(2)
					);
				((LINE*)cur)->dir_ = dir;
				((LINE*)cur)->magnitude_ = line->dir()->magnitude();
				 
			}
			if(!strcmp(pcurve->className(), "circle"))
			{
				stp_circle* cir = ROSE_CAST(stp_circle, pcurve);
				GetAxisData(cir->position()->_axis2_placement_3d(), tempGepmetry);
				((CIRCLE*)cur)->position_ = tempGepmetry;
				((CIRCLE*)cur)->radius_ = cir->radius();
			}
			if(!strcmp(pcurve->className(), "ellipse"))
			{
				stp_ellipse* ell = ROSE_CAST(stp_ellipse, pcurve);
				GetAxisData(ell->position()->_axis2_placement_3d(), tempGepmetry);
				((ELLIPSE*)cur)->position_ = tempGepmetry;
				((ELLIPSE*)cur)->semi_axis_1_ = ell->semi_axis_1();
				((ELLIPSE*)cur)->semi_axis_2_ = ell->semi_axis_2();
			}
			cur->curveName_ = pcurve->className();
			stp_cartesian_point* eStart = EdgeCurveStartOrEnd(curve->edge_start());
			stp_cartesian_point* eEnd = EdgeCurveStartOrEnd(curve->edge_end());
			CPoint3D start(eStart->coordinates()->get(0), eStart->coordinates()->get(1), eStart->coordinates()->get(2));
			CPoint3D end(eEnd->coordinates()->get(0), eEnd->coordinates()->get(1), eEnd->coordinates()->get(2));
			cur->edgeStart_ = start;
			cur->edgeEnd_ = end;
			cur->edgeCurvesameSense_ = curve->same_sense();
			cur->orientedEdgeOri_ = oriEdge->orientation();
			curveTemp.push_back(cur);
		}
		faceB->edgeLoop_ = curveTemp;
		faceB->boundsOri_ = bound->orientation();
		faceBounds.push_back(faceB);
		vector<Curve*>().swap(curveTemp);
	}

	if(!strcmp(entityName, "plane"))
	{
		SPlane* surface = new SPlane;
		stp_plane* plane = ROSE_CAST(stp_plane, adFace->face_geometry());
		stp_axis2_placement_3d* axis = plane->position();
		GeometryData* data = new GeometryData;
		GetAxisData(axis, *data);
		surface->entityID_ = adFace->entity_id();
		surface->name_ = entityName;
		surface->position_ = data;
		surface->faceBounds_ = faceBounds;
		NatlHalfSpaceList_.push_back(surface);
	}
	else if(!strcmp(entityName, "spherical_surface"))
	{
		SSpherical* surface = new SSpherical;
		stp_spherical_surface* spherical = ROSE_CAST(stp_spherical_surface, adFace->face_geometry());
		stp_axis2_placement_3d* axis3D = spherical->position();
		GeometryData* data = new GeometryData;
		GetAxisData(axis3D, *data);
		surface->entityID_ = adFace->entity_id();
		surface->name_ = entityName;
		surface->radius_ = spherical->radius() / ZOOMTIME;
		surface->position_ = data;
		surface->faceBounds_ = faceBounds;
		NatlHalfSpaceList_.push_back(surface);

	}
	else if(!strcmp(entityName, "conical_surface"))
	{
		SConical* surface = new SConical;
		stp_conical_surface* conical = ROSE_CAST(stp_conical_surface, adFace->face_geometry());
		stp_axis2_placement_3d* axis3D = conical->position();
		GeometryData* data = new GeometryData;
		GetAxisData(axis3D, *data);
		surface->entityID_ = adFace->entity_id();
		surface->name_ = entityName;
		surface->radius_ = conical->radius();
		surface->semi_angle_ = conical->semi_angle() / ZOOMTIME;
		surface->position_ = data;
		surface->faceBounds_ = faceBounds;
		NatlHalfSpaceList_.push_back(surface);
	}
	else if(!strcmp(entityName, "cylindrical_surface"))
	{
		SCylindrical* surface = new SCylindrical;
		stp_cylindrical_surface* cylindrical = ROSE_CAST(stp_cylindrical_surface, adFace->face_geometry());
		stp_axis2_placement_3d* axis3D = cylindrical->position();
		GeometryData* data = new GeometryData;
		GetAxisData(axis3D, *data);
		surface->entityID_ = adFace->entity_id();
		surface->name_ = entityName;
		surface->radius_ = cylindrical->radius() / ZOOMTIME;
		surface->position_ = data;
		surface->faceBounds_ = faceBounds;
		NatlHalfSpaceList_.push_back(surface);
	}
	else if(!strcmp(entityName, "toroidal_surface"))
	{
		SToroidal* surface = new SToroidal;
		stp_toroidal_surface* toroidal = ROSE_CAST(stp_toroidal_surface, adFace->face_geometry());
		stp_axis2_placement_3d* axis3D = toroidal->position();
		GeometryData* data = new GeometryData;
		GetAxisData(axis3D, *data);
		surface->entityID_ = adFace->entity_id();
		surface->name_ = entityName;
		surface->major_radius_ = toroidal->major_radius();
		surface->minor_radius_ = toroidal->minor_radius();
		surface->position_ = data;
		surface->faceBounds_ = faceBounds;
		NatlHalfSpaceList_.push_back(surface);
	}
	vector<FaceBounds*>().swap(faceBounds);
}
Esempio n. 4
0
stp_cartesian_point* Partition::EdgeCurveStartOrEnd(stp_vertex* ver)
{
	stp_vertex_point * vpt = ROSE_CAST(stp_vertex_point, ver);
	return ROSE_CAST(stp_cartesian_point, vpt->vertex_geometry());
}
Esempio n. 5
0
void Partition::StepConversionAndOutput()
{
	RoseCursor objects;
	RoseObject* obj;
	objects.traverse(design_);
	objects.domain(ROSE_DOMAIN(stp_advanced_brep_shape_representation));
	int m = 1;
	int n = 1;
	while(obj = objects.next())
	{
		stp_advanced_brep_shape_representation* pt = ROSE_CAST(stp_advanced_brep_shape_representation, obj);
		SetOfstp_representation_item* items = pt->items();
		stp_representation_context* item = pt->context_of_items();
		for(size_t i = 0; i < items->size(); i++)
		{
			stp_representation_item* it = items->get(i);
			if(!strcmp("axis2_placement_3d", it->className()))
				stp_axis2_placement_3d *axis = ROSE_CAST(stp_axis2_placement_3d, it);
			if(!strcmp("manifold_solid_brep", it->className()))
			{
				stp_manifold_solid_brep* solidBrep = ROSE_CAST(stp_manifold_solid_brep, it);
				stp_closed_shell* shell = solidBrep->outer();
				SetOfstp_face* face = shell->cfs_faces();
				GetSFaceInfo(face);

				StepEntity* step = new StepEntity(intersectionFaceList_);
				step->GenerateHalfSpaceList();
				step->GenerateCIT();
				step->GenerateHalfCharacteristicPoint();
				step->PMCtest();
				step->Output(&m, &n, "", vecOut_, false, false, false, false);
			}
			if(!strcmp("brep_with_voids", it->className()))
			{
				stp_brep_with_voids* voidsBrep = ROSE_CAST(stp_brep_with_voids, it);
				stp_closed_shell* shell = voidsBrep->outer();
				SetOfstp_face* face = shell->cfs_faces();
				GetSFaceInfo(face);

				StepEntity* step = new StepEntity(intersectionFaceList_);
				step->GenerateHalfSpaceList();
				step->GenerateCIT();
				step->GenerateHalfCharacteristicPoint();
				step->PMCtest();
				step->Output(&m, &n, "", vecOut_, false, false, false, false);

 				SetOfstp_oriented_closed_shell* orientedShell = voidsBrep->voids();
				for(size_t i = 0; i < orientedShell->size(); i++)
				{
					stp_oriented_closed_shell* oriClosedShell = orientedShell->get(i);
					stp_closed_shell* closeShell = oriClosedShell->closed_shell_element();
					SetOfstp_face* face = closeShell->cfs_faces();
					GetSFaceInfo(face);

					StepEntity* step = new StepEntity(intersectionFaceList_);
					step->GenerateHalfSpaceList();
					step->GenerateCIT();
					step->GenerateHalfCharacteristicPoint();
					step->PMCtest();
					step->Output(&m, &n, "", vecOut_, false, false, false, false);
				}
			}
		}
	}
}