mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
Foundation Classes - TopoDS_Shape accept scaling by default #239
Refactor Location and Move methods to validate transformations. New default value to raise exception is false.
This commit is contained in:
parent
a4443d74ad
commit
9687f7369c
@ -85,23 +85,24 @@ public:
|
||||
const TopLoc_Location& Location() const { return myLocation; }
|
||||
|
||||
//! Sets the shape local coordinate system.
|
||||
void Location (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_True)
|
||||
//! @param theLoc the new local coordinate system.
|
||||
//! @param theRaiseExc flag to raise exception in case of transformation with scale or negative.
|
||||
void Location (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_False)
|
||||
{
|
||||
const gp_Trsf& aTrsf = theLoc.Transformation();
|
||||
if ((Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec() || aTrsf.IsNegative()) && theRaiseExc)
|
||||
if (theRaiseExc)
|
||||
{
|
||||
//Exception
|
||||
throw Standard_DomainError("Location with scaling transformation is forbidden");
|
||||
}
|
||||
else
|
||||
{
|
||||
myLocation = theLoc;
|
||||
validateTransformation(aTrsf);
|
||||
}
|
||||
myLocation = theLoc;
|
||||
}
|
||||
|
||||
//! Returns a shape similar to <me> with the local
|
||||
//! Returns a shape similar to <me> with the local
|
||||
//! coordinate system set to <Loc>.
|
||||
TopoDS_Shape Located (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_True) const
|
||||
//! @param theLoc the new local coordinate system.
|
||||
//! @param theRaiseExc flag to raise exception in case of transformation with scale or negative.
|
||||
//! @return the located shape.
|
||||
TopoDS_Shape Located (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_False) const
|
||||
{
|
||||
TopoDS_Shape aShape (*this);
|
||||
aShape.Location (theLoc, theRaiseExc);
|
||||
@ -182,22 +183,23 @@ public:
|
||||
void Convex (Standard_Boolean theIsConvex) { myTShape->Convex (theIsConvex); }
|
||||
|
||||
//! Multiplies the Shape location by thePosition.
|
||||
void Move(const TopLoc_Location& thePosition, const Standard_Boolean theRaiseExc = Standard_True)
|
||||
//! @param thePosition the transformation to apply.
|
||||
//! @param theRaiseExc flag to raise exception in case of transformation with scale or negative.
|
||||
void Move(const TopLoc_Location& thePosition, const Standard_Boolean theRaiseExc = Standard_False)
|
||||
{
|
||||
const gp_Trsf& aTrsf = thePosition.Transformation();
|
||||
if ((Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec() || aTrsf.IsNegative()) && theRaiseExc)
|
||||
if (theRaiseExc)
|
||||
{
|
||||
//Exception
|
||||
throw Standard_DomainError("Moving with scaling transformation is forbidden");
|
||||
}
|
||||
else
|
||||
{
|
||||
myLocation = thePosition * myLocation;
|
||||
validateTransformation(aTrsf);
|
||||
}
|
||||
myLocation = thePosition * myLocation;
|
||||
}
|
||||
|
||||
//! Returns a shape similar to <me> with a location multiplied by thePosition.
|
||||
TopoDS_Shape Moved (const TopLoc_Location& thePosition, const Standard_Boolean theRaiseExc = Standard_True) const
|
||||
//! @param thePosition the transformation to apply.
|
||||
//! @param theRaiseExc flag to raise exception in case of transformation with scale or negative.
|
||||
//! @return the moved shape.
|
||||
TopoDS_Shape Moved (const TopLoc_Location& thePosition, const Standard_Boolean theRaiseExc = Standard_False) const
|
||||
{
|
||||
TopoDS_Shape aShape (*this);
|
||||
aShape.Move (thePosition, theRaiseExc);
|
||||
@ -300,6 +302,20 @@ public:
|
||||
//! Dumps the content of me into the stream
|
||||
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
|
||||
|
||||
protected:
|
||||
|
||||
//! Checks if the transformation contains scaling or negative values.
|
||||
//! Raises an exception if the transformation is invalid.
|
||||
//! @param theTrsf transformation to validate
|
||||
void validateTransformation(const gp_Trsf& theTrsf) const
|
||||
{
|
||||
if (Abs(Abs(theTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec() || theTrsf.IsNegative())
|
||||
{
|
||||
//Exception
|
||||
throw Standard_DomainError("Transformation with scaling transformation is forbidden");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Handle(TopoDS_TShape) myTShape;
|
||||
|
Loading…
x
Reference in New Issue
Block a user