Solids improperly translated at import

When importing a multi-part model, the relative positions of the solids are incorrect (see images: gear1 is taken after importing the model into FreeCAD, and gear2 after loading the same model into my program). Can anyone suggest what I might look at to recover the proper orientation of the imported solids? Thanks in advance for any suggestions.

Attachments: 
Dmitrii Pasukhin's picture

Hello,
Can you share more details about your scenario,
Which interface are you using and what is the CAD format? It is single file or different(not related) or it is connected files by reference?

Best regards, Dmitrii.

Lee Kania's picture

Thank you for responding. I've attached the model I am attempting to load as a zipped step file. The pedigree of this model is unknown to me as I simply pulled it from GrabCAD, but it is a single file containing two solids. When I import this into FreeCAD the parts are oriented as I would expect (see gear1.png), but I am unable to achieve the same result using my own reader:
.
.
.
IFSelect_ReturnStatus stat = myReader.ReadFile(File);
if (stat == IFSelect_RetDone)
{
printf("Model file %s was successfully imported via OpenCascade.\n", File);
return true;
}
else
{
return false;
}
.
.
.
Standard_Integer numRoots = myReader.NbRootsForTransfer();
printf("Number of roots: %d\n", numRoots);
myReader.TransferRoots();
.
.
.
TopExp_Explorer exp;
TopoDS_Shape myShape;
Standard_Integer numShapes = myReader.NbShapes();
for (Standard_Integer i = 1; i <= numShapes; i++)
{
myShape = myReader.Shape(i);
for (exp.Init(myShape, TopAbs_SOLID); exp.More(); exp.Next())
{
TopoDS_Shape shape = exp.Current();
if(shape.ShapeType() == TopAbs_SOLID)
{
TopoDS_Solid solid = TopoDS::Solid(shape);
std::shared_ptr<Dis::Vol::ModelVolume> modelVolume(new Dis::Vol::ModelVolume(solid));
ModelVolumes.push_back(modelVolume);
// compute volume
GProp_GProps gprops;
BRepGProp::VolumeProperties(solid, gprops, 0.001, Standard_True);
modelVolume->SetVolume(gprops.Mass());
}
}
}

The model imports successfully, and I ultimately retrieve references to each TopoDS_Face object bounding each solid, generate a tessellation for each, and then export these for viewing. What I am getting is shown in the gear2.png image I had posted earlier.

My question is how might I go about retrieving and applying any transformation that might be associated with a particular TopoDS_Solid so that all solids within the assembly are properly oriented.

Attachments: 
Dmitrii Pasukhin's picture

"TopExp_Explorer" I'm not sure about keeping the location via iteration. Reading return correct shape. Please check that iteration return solids with transfromation(not identity at least). In you file each root has own location.

Best regards, Dmitrii.

Lee Kania's picture

Thank you for hanging on with this!
You can see from the attached image (gears3.png) that each of the solids is positioned at the origin of the global coordinate system after processing with my code.
While iterating over the shapes, I have inserted the two new statements to retrieve the Location and associated Transformation:
TopoDS_Shape shape = exp.Current();
TopLoc_Location Locate = shape.Location();
gp_Trsf Trans = Locate.Transformation();
For the first solid, Trans contains the matrix:
0, 0, -1
0, 1, 0
1, 0, 0
and location vector:
0,0,0
while for the second solid, Trans contains:
1, 0, 0
0, 1, 0
0, 0, 1
and location vector:
65.1, 0., -107.5

Is it just a matter of applying this transformation data to the solids? If so, I'm not quite sure of the method available to perform this.

Attachments: 
Lee Kania's picture

.

Lee Kania's picture

See previous comment.

Dmitrii Pasukhin's picture

Thank you. It means that everyting is correct. I just thinking about extracting mesh functionality. Pure mesh has no location, it means you must to transform mesh by yourself.

Best regards, Dmitrii.

Lee Kania's picture

Fell right out after introducing the transformation on the mesh.

Many thanks,

Lee