private Vector3 getHoverPos(LineElement line, GraphicView activeView, Point location, Model.Model model, View.Renderer.RenderOptions options)
{
Vector3 pos = Vector3.Empty;
bool lastUndoEnabled = model.Undo.Enabled;
bool lastUnitSystemEnabled = Model.UnitSystem.UnitSystemsManager.Instance.Enabled;
if (!model.HasResults || model.Results.ActiveCase == null)
return pos;
try
{
if (model.IsLocked)
model.Undo.Enabled = false;
Model.UnitSystem.UnitSystemsManager.Instance.Enabled = false;
int numPoints = (int)options.LOD.GetLOD(line).LODSegments + 1;
float[] xPos;
Analysis.LineDeformationCalculator calc = new Analysis.LineDeformationCalculator();
curve = calc.GetCurve(line, model.Results.ActiveCase.AbstractCase, numPoints, options.DeformationScale, model.Results.PaintScaleFactorTranslation, out xPos);
int iCurve = 0, numLines = curve.Length - 1;
Snap.LineMagnet minLine = null, lm;
float minLineDist = float.MaxValue, lineDist;
for (int i = 0; i < numLines; i++)
{
lm = new Canguro.Controller.Snap.LineMagnet(curve[i], curve[i + 1] - curve[i], Canguro.Controller.Snap.LineMagnetType.FollowProjection);
if ((lineDist = lm.Snap(activeView, location)) < minLineDist)
{
if ((lm.SnapPositionInt - curve[i]).LengthSq() <= (curve[i + 1] - curve[i]).LengthSq())
{
minLineDist = lineDist;
minLine = lm;
iCurve = i;
}
}
}
if (minLine != null)
{
pos = minLine.SnapPositionInt;
lm = new Canguro.Controller.Snap.LineMagnet(curve[iCurve], curve[iCurve + 1] - curve[iCurve], Canguro.Controller.Snap.LineMagnetType.FollowProjection);
Vector3 tmp = pos - curve[0];
Vector3 xPosUnit = curve[numLines] - curve[0];
xPosUnit = Vector3.Scale(xPosUnit, 1.0f / xPosUnit.LengthSq());
hoverXPos = Vector3.Dot(tmp, xPosUnit);
}
else
hoverItem = null;
}
finally
{
Model.UnitSystem.UnitSystemsManager.Instance.Enabled = lastUnitSystemEnabled;
model.Undo.Enabled = lastUndoEnabled;
}
return pos;
}