Improvement of rotations

Rotation:
-	Add a private attribute Vector to store the direction of the rotation, and manage not to erase this direction when the angle id 0.
-	Add a private attribute to store the angle as defined (no modulo etc)
-	Keep the quaternion for calculations

PropertyGeo
-	Saves the rotation with angle and direction instead of saving the quaternion.
-	Attribute name chosen: Ox, Oy and Oz for the coordinates of the axis and A for the angle in radians. This has to be validated.
-	Backward compatibility with the saved files with quaternion (test presence of A to determine which of  the Quaternion (old way) or the direction and angle is stored (new way). New files can be opened by old FreeCAD and vice-versa.

The only side effect I can imagine is that it was possible to set a vector to 0, 0, 0 if the angle was not 0, what is somehow non sense. Now when setting to 0, 0 0 the last not null vector is kept. The vector can not be null any longer.
This commit is contained in:
plgarcia
2017-11-20 00:36:01 +01:00
committed by wmayer
parent e272f02e59
commit a0ea3ceec9
3 changed files with 120 additions and 34 deletions

View File

@@ -744,10 +744,18 @@ void PropertyPlacement::Save (Base::Writer &writer) const
writer.Stream() << " Px=\"" << _cPos.getPosition().x
<< "\" Py=\"" << _cPos.getPosition().y
<< "\" Pz=\"" << _cPos.getPosition().z << "\"";
writer.Stream() << " Q0=\"" << _cPos.getRotation()[0]
<< "\" Q1=\"" << _cPos.getRotation()[1]
<< "\" Q2=\"" << _cPos.getRotation()[2]
<< "\" Q3=\"" << _cPos.getRotation()[3] << "\"";
Vector3d axis;
double rfAngle;
_cPos.getRotation().getValue(axis, rfAngle);
writer.Stream() << " A=\"" << rfAngle
<< "\" Ox=\"" << axis.x
<< "\" Oy=\"" << axis.y
<< "\" Oz=\"" << axis.z << "\"";
writer.Stream() <<"/>" << endl;
}
@@ -757,13 +765,25 @@ void PropertyPlacement::Restore(Base::XMLReader &reader)
reader.readElement("PropertyPlacement");
// get the value of my Attribute
aboutToSetValue();
_cPos = Base::Placement(Vector3d(reader.getAttributeAsFloat("Px"),
if (reader.hasAttribute("A")) {
_cPos = Base::Placement(Vector3d(reader.getAttributeAsFloat("Px"),
reader.getAttributeAsFloat("Py"),
reader.getAttributeAsFloat("Pz")),
Rotation(
Vector3d(reader.getAttributeAsFloat("Ox"),
reader.getAttributeAsFloat("Oy"),
reader.getAttributeAsFloat("Oz")),
reader.getAttributeAsFloat("A")));
} else {
_cPos = Base::Placement(Vector3d(reader.getAttributeAsFloat("Px"),
reader.getAttributeAsFloat("Py"),
reader.getAttributeAsFloat("Pz")),
Rotation(reader.getAttributeAsFloat("Q0"),
reader.getAttributeAsFloat("Q1"),
reader.getAttributeAsFloat("Q2"),
reader.getAttributeAsFloat("Q3")));
}
hasSetValue();
}