mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-13 10:10:34 +05:00
Slight improvement and refactoring of dimension displaying
This commit is contained in:
parent
b13e4d9ce0
commit
739bac212f
@ -103,6 +103,11 @@ private:
|
|||||||
bool& myLock;
|
bool& myLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool isSame (double d1, double d2)
|
||||||
|
{
|
||||||
|
return Abs(d1 - d2) <= Precision::Confusion();
|
||||||
|
}
|
||||||
|
|
||||||
//=================================================================================
|
//=================================================================================
|
||||||
// class : EntityGUI_3DSketcherDlg()
|
// class : EntityGUI_3DSketcherDlg()
|
||||||
// purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
|
// purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
|
||||||
@ -1133,65 +1138,43 @@ gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
|
|||||||
|
|
||||||
gp_Vec Vec1(P1,P2);
|
gp_Vec Vec1(P1,P2);
|
||||||
gp_Vec Vec2(P1,P3);
|
gp_Vec Vec2(P1,P3);
|
||||||
gp_Vec Vec3 = Vec1;
|
|
||||||
|
|
||||||
gp_Dir aNormal; // Normal defining the plane of the presentation
|
gp_Dir aNormal; // Normal defining the plane of the presentation
|
||||||
|
|
||||||
if (withAngle) // If one angle
|
if (withAngle) // If one angle
|
||||||
{
|
{
|
||||||
switch(myOrientation)
|
// Transformation from the current coordinate system
|
||||||
{
|
// to the reference coordinate system
|
||||||
case OXY:
|
gp_Trsf aTransform = toReferenceSystem (P1);
|
||||||
{
|
gp_Dir N1 = gp::DZ();
|
||||||
if (Vec1.CrossMagnitude(gp::DZ()) > Precision::Confusion())
|
gp_Dir N2 = gp::DY();
|
||||||
aNormal = gp::DZ().Crossed(gp_Dir(Vec1)); // --> the plane is orthogonal to the angle presentation
|
N1.Transform(aTransform);
|
||||||
else // plane and contains the current edge
|
N2.Transform(aTransform);
|
||||||
aNormal = gp::DY();
|
|
||||||
|
|
||||||
if (twoAngles) // If two angles
|
if (Vec1.CrossMagnitude(N1) > Precision::Confusion())
|
||||||
{
|
{
|
||||||
gp_XYZ Vec1_XY(Vec1.X(),Vec1.Y(),0.0);// --> define Vec3 as the projection of the current
|
// The plane is orthogonal to the angle presentation plane
|
||||||
Vec3 = gp_Vec(Vec1_XY); // edge on the plane chosen for the first angle
|
// and contains the current edge
|
||||||
|
aNormal = N1.Crossed(gp_Dir(Vec1));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OYZ:
|
|
||||||
{
|
|
||||||
if (Vec1.CrossMagnitude(gp::DX()) > Precision::Confusion())
|
|
||||||
aNormal = gp::DX().Crossed(gp_Dir(Vec1));
|
|
||||||
else
|
else
|
||||||
aNormal = gp::DZ();
|
aNormal = N2;
|
||||||
|
|
||||||
if (twoAngles)
|
if (twoAngles)
|
||||||
{
|
{
|
||||||
gp_XYZ Vec1_YZ(0.0,Vec1.Y(),Vec1.Z());
|
gp_Vec V = Vec1.Transformed(aTransform.Inverted());
|
||||||
Vec3 = gp_Vec(Vec1_YZ);
|
gp_Vec Vec3(V.X(),V.Y(),0.0);
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OXZ:
|
|
||||||
{
|
|
||||||
if (Vec1.CrossMagnitude(gp::DY()) > Precision::Confusion())
|
|
||||||
aNormal = gp::DY().Crossed(gp_Dir(Vec1));
|
|
||||||
else
|
|
||||||
aNormal = gp::DZ();
|
|
||||||
|
|
||||||
if (twoAngles)
|
// Express the coordinates in the refernce coordinate system (OXY)
|
||||||
|
Vec3.Transform(aTransform);
|
||||||
|
if(Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
|
||||||
{
|
{
|
||||||
gp_XYZ Vec1_XZ(Vec1.X(),0.0,Vec1.Z());
|
// set the normal as the cross product of the current edge with its projection
|
||||||
Vec3 = gp_Vec(Vec1_XZ);
|
// it ensures that the dimension changes side when the angle becomes negative
|
||||||
}
|
aNormal = gp_Dir(Vec1.Crossed(Vec3));
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(twoAngles // If two angles
|
|
||||||
&& Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
|
|
||||||
{
|
|
||||||
aNormal = gp_Dir(Vec1.Crossed(Vec3));// --> set the normal as the cross product of
|
|
||||||
} // the current edge with its projection
|
|
||||||
} // it ensures that the dimension changes
|
|
||||||
// side when the angle becomes negative
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check colinearity
|
// Check colinearity
|
||||||
@ -1203,8 +1186,9 @@ gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
|
|||||||
Vec2 = gp_Vec(gp::DY());
|
Vec2 = gp_Vec(gp::DY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aNormal = gp_Dir(Vec1.Crossed(Vec2)); // If no angles --> the plane is the one formed by
|
// If no angles, the plane is the one formed by the last edge and the current one
|
||||||
} // the last edge and the current one
|
aNormal = gp_Dir(Vec1.Crossed(Vec2));
|
||||||
|
}
|
||||||
return aNormal;
|
return aNormal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1309,9 +1293,12 @@ void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
|
|||||||
XYZ Current = getCurrentPoint();
|
XYZ Current = getCurrentPoint();
|
||||||
|
|
||||||
gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
|
gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
|
||||||
|
|
||||||
gp_Pnt P0 = Last_Pnt;
|
gp_Pnt P0 = Last_Pnt;
|
||||||
|
gp_Pnt Origin = gp::Origin();
|
||||||
if (myMode == 0) // Absolute coordinates
|
if (myMode == 0) // Absolute coordinates
|
||||||
P0=gp::Origin();
|
P0 = Origin;
|
||||||
|
|
||||||
gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
|
gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
|
||||||
gp_Pnt P1, P2;
|
gp_Pnt P1, P2;
|
||||||
|
|
||||||
@ -1323,21 +1310,25 @@ void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
|
|||||||
|
|
||||||
if (myCoordType == 0)
|
if (myCoordType == 0)
|
||||||
{
|
{
|
||||||
if((( Abs(Last.x-Current.x) <= Precision::Confusion() &&
|
bool oneDimensionalMove = (isSame(Last_Pnt.X(), Current_Pnt.X()) &&
|
||||||
Abs(Last.y-Current.y) <= Precision::Confusion() ) ||
|
isSame(Last_Pnt.Y(), Current_Pnt.Y()) ) ||
|
||||||
( Abs(Last.x-Current.x) <= Precision::Confusion() &&
|
(isSame(Last_Pnt.Y(), Current_Pnt.Y()) &&
|
||||||
Abs(Last.z-Current.z) <= Precision::Confusion() ) ||
|
isSame(Last_Pnt.Z(), Current_Pnt.Z()) ) ||
|
||||||
( Abs(Last.y-Current.y) <= Precision::Confusion() &&
|
(isSame(Last_Pnt.X(), Current_Pnt.X()) &&
|
||||||
Abs(Last.z-Current.z) <= Precision::Confusion() ))&&
|
isSame(Last_Pnt.Z(), Current_Pnt.Z()) );
|
||||||
myMode == 1)
|
|
||||||
|
if(oneDimensionalMove && myMode == 1)
|
||||||
{
|
{
|
||||||
// For better colocation of dimensions if only one coordinate changes (aNormal is a better choice)
|
// For better colocation of dimensions if only one coordinate changes (aNormal is a better choice)
|
||||||
displayLength(P0, Current_Pnt, aNormal, store);
|
displayLength(P0, Current_Pnt, aNormal, store);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!isSame(Last_Pnt.X(),Current_Pnt.X()))
|
||||||
displayLength(gp_Pnt(P0.X(),Current.y,P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ().Reversed(), store);
|
displayLength(gp_Pnt(P0.X(),Current.y,P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ().Reversed(), store);
|
||||||
|
if (!isSame(Last_Pnt.Y(),Current_Pnt.Y()))
|
||||||
displayLength(gp_Pnt(Current.x,P0.Y(),P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ(), store);
|
displayLength(gp_Pnt(Current.x,P0.Y(),P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ(), store);
|
||||||
|
if (!isSame(Last_Pnt.Z(),Current_Pnt.Z()))
|
||||||
displayLength(gp_Pnt(Current.x,Current.y,P0.Z()), Current_Pnt, gp::DX(), store);
|
displayLength(gp_Pnt(Current.x,Current.y,P0.Z()), Current_Pnt, gp::DX(), store);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1349,36 +1340,19 @@ void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
|
|||||||
double anAngle1 = GroupAngles->SpinBox_DA->value();
|
double anAngle1 = GroupAngles->SpinBox_DA->value();
|
||||||
double aLength = GroupAngles->SpinBox_DL->value();
|
double aLength = GroupAngles->SpinBox_DL->value();
|
||||||
|
|
||||||
switch(myOrientation)
|
// Set the coordinates in the current coordinate system
|
||||||
{
|
P1.SetCoord( aLength, 0.0, 0.0); // X direction
|
||||||
case OXY:
|
P2.SetCoord( aLength * cos(anAngle1 * M_PI / 180. ),
|
||||||
{
|
aLength * sin(anAngle1 * M_PI / 180. ),
|
||||||
P1 = gp_Pnt(P0.X() + aLength,P0.Y(),P0.Z()); // X direction
|
0.0);
|
||||||
P2 = gp_Pnt(P0.X() + aLength * cos(anAngle1 * M_PI / 180.),
|
|
||||||
P0.Y() + aLength * sin(anAngle1 * M_PI / 180.),
|
// Express the coordinates in the refernce coordinate system (OXY)
|
||||||
P0.Z());
|
gp_Trsf aTranform = toReferenceSystem(P0);
|
||||||
break;
|
P1.Transform(aTranform);
|
||||||
}
|
P2.Transform(aTranform);
|
||||||
case OYZ:
|
P1.Translate(Origin, P0);
|
||||||
{
|
P2.Translate(Origin, P0);
|
||||||
P1 = gp_Pnt(P0.X(), P0.Y() + aLength,P0.Z()); // Y direction
|
|
||||||
P2 = gp_Pnt(P0.X(),
|
|
||||||
P0.Y() + aLength * cos(anAngle1 * M_PI / 180.),
|
|
||||||
P0.Z() + aLength * sin(anAngle1 * M_PI / 180.));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OXZ:
|
|
||||||
{
|
|
||||||
P1 = gp_Pnt(P0.X() + aLength,P0.Y(),P0.Z()); // X direction
|
|
||||||
P2 = gp_Pnt(P0.X() + aLength * cos(anAngle1 * M_PI / 180.) ,
|
|
||||||
P0.Y(),
|
|
||||||
P0.Z() + aLength * sin(anAngle1 * M_PI / 180.));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!cylindrical)
|
|
||||||
displayLength(P0, Current_Pnt, aNormal, store);
|
|
||||||
if(myMode !=0 || !store)
|
if(myMode !=0 || !store)
|
||||||
displayAngle(anAngle1, P0, P1, P2, store);
|
displayAngle(anAngle1, P0, P1, P2, store);
|
||||||
|
|
||||||
@ -1386,14 +1360,24 @@ void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
|
|||||||
{
|
{
|
||||||
double anAngle2 = GroupAngles->SpinBox_DA2->value();
|
double anAngle2 = GroupAngles->SpinBox_DA2->value();
|
||||||
displayAngle(anAngle2, P0, P2, Current_Pnt, store);
|
displayAngle(anAngle2, P0, P2, Current_Pnt, store);
|
||||||
|
displayLength(P0, Current_Pnt, aNormal, store);
|
||||||
}
|
}
|
||||||
if(cylindrical)
|
|
||||||
{
|
|
||||||
gp_Vec aVec(P2, Current_Pnt);
|
|
||||||
if (myMode == 0)
|
|
||||||
displayLength(P0.Translated(aVec), P2.Translated(aVec), aNormal, store); // Radius
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
bool sameRadius = isSame ( radius(Last_Pnt), radius(Current_Pnt) );
|
||||||
|
bool sameHeight = isSame ( height(Last_Pnt), height(Current_Pnt) );
|
||||||
|
|
||||||
|
gp_Vec aVec(P2, Current_Pnt);
|
||||||
|
|
||||||
|
if (myMode == 0 && !sameRadius)
|
||||||
|
{
|
||||||
|
displayLength(P0.Translated(aVec), P2.Translated(aVec), aNormal, store); // Radius
|
||||||
|
}
|
||||||
|
else if (myMode == 1)
|
||||||
displayLength(P0, P2, aNormal, store);
|
displayLength(P0, P2, aNormal, store);
|
||||||
|
|
||||||
|
if ( cylindrical &&
|
||||||
|
(myMode == 1 || !sameHeight) )
|
||||||
displayLength(P2, Current_Pnt, aNormal.Reversed(), store); // Height
|
displayLength(P2, Current_Pnt, aNormal.Reversed(), store); // Height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1663,3 +1647,69 @@ std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
|
|||||||
|
|
||||||
return QString::number(num, format, digNum).toStdString();
|
return QString::number(num, format, digNum).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Function : toReferenceSystem ()
|
||||||
|
// Purpose :
|
||||||
|
//================================================================
|
||||||
|
gp_Trsf EntityGUI_3DSketcherDlg::toReferenceSystem(gp_Pnt origin) const
|
||||||
|
{
|
||||||
|
gp_Trsf T; // Identity transformation
|
||||||
|
gp_Ax3 reference_system; // OXY
|
||||||
|
reference_system.SetLocation(origin);
|
||||||
|
|
||||||
|
gp_Ax3 current_system = reference_system;
|
||||||
|
switch (myOrientation)
|
||||||
|
{
|
||||||
|
case OYZ:
|
||||||
|
{
|
||||||
|
current_system = gp_Ax3(origin, gp::DX(), gp::DY());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OXZ:
|
||||||
|
{
|
||||||
|
current_system = gp_Ax3(origin, gp::DY().Reversed(), gp::DX());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T.SetTransformation( current_system, reference_system );
|
||||||
|
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Function : toCurrentSystem ()
|
||||||
|
// Purpose :
|
||||||
|
//================================================================
|
||||||
|
gp_Trsf EntityGUI_3DSketcherDlg::toCurrentSystem(gp_Pnt origin) const
|
||||||
|
{
|
||||||
|
return toReferenceSystem(origin).Inverted();
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Function : radius (gp_Pnt) const
|
||||||
|
// Purpose :
|
||||||
|
//================================================================
|
||||||
|
double EntityGUI_3DSketcherDlg::radius (gp_Pnt thePnt) const
|
||||||
|
{
|
||||||
|
// Get the point coordinates in the current coordinates system
|
||||||
|
gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
|
||||||
|
gp_Pnt aPnt = thePnt.Transformed(aTrsf);
|
||||||
|
|
||||||
|
double radius = sqrt(aPnt.X()*aPnt.X() + aPnt.Y()*aPnt.Y());
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Function : height (gp_Pnt) const
|
||||||
|
// Purpose :
|
||||||
|
//================================================================
|
||||||
|
double EntityGUI_3DSketcherDlg::height (gp_Pnt thePnt) const
|
||||||
|
{
|
||||||
|
// Get the point coordinates in the current coordinates system
|
||||||
|
gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
|
||||||
|
gp_Pnt aPnt = thePnt.Transformed(aTrsf);
|
||||||
|
|
||||||
|
return aPnt.Z();
|
||||||
|
}
|
@ -45,6 +45,9 @@ class gp_Dir;
|
|||||||
# define DBL_DIGITS_DISPLAY 16
|
# define DBL_DIGITS_DISPLAY 16
|
||||||
#endif // COORD_MIN
|
#endif // COORD_MIN
|
||||||
|
|
||||||
|
// For convenience
|
||||||
|
bool isSame (double d1, double d2);
|
||||||
|
|
||||||
//=================================================================================
|
//=================================================================================
|
||||||
// class : EntityGUI_Dlg
|
// class : EntityGUI_Dlg
|
||||||
// purpose :
|
// purpose :
|
||||||
@ -131,9 +134,17 @@ private:
|
|||||||
|
|
||||||
std::string doubleToString( double );
|
std::string doubleToString( double );
|
||||||
|
|
||||||
|
gp_Trsf toReferenceSystem(gp_Pnt origin) const;
|
||||||
|
gp_Trsf toCurrentSystem(gp_Pnt origin) const;
|
||||||
|
|
||||||
void removeLastIOFromPrs();
|
void removeLastIOFromPrs();
|
||||||
void restoreLastIOToPrs();
|
void restoreLastIOToPrs();
|
||||||
|
|
||||||
|
double radius(gp_Pnt) const;
|
||||||
|
double height(gp_Pnt) const;
|
||||||
|
double longitude(gp_Pnt) const;
|
||||||
|
double latitude(gp_Pnt) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XYZList myPointsList;
|
XYZList myPointsList;
|
||||||
XYZList myRedoList;
|
XYZList myRedoList;
|
||||||
|
Loading…
Reference in New Issue
Block a user