1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0031326: Foundation Classes - Init from Json for base OCCT classes

InitFromJson method implementation for some simple classes.
OCCT_INIT_* defines introduction to do automatic parsing of the stream into values.
Inspector is extended to visualize objects created on the dump stream if it might be created.
This commit is contained in:
nds
2020-09-08 00:16:32 +03:00
committed by bugmaster
parent b19cde437e
commit 6b63dc83c3
33 changed files with 793 additions and 63 deletions

View File

@@ -90,3 +90,20 @@ void gp_Ax1::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
OCCT_DUMP_VECTOR_CLASS (theOStream, "Location", 3, loc.X(), loc.Y(), loc.Z())
OCCT_DUMP_VECTOR_CLASS (theOStream, "Direction", 3, vdir.X(), vdir.Y(), vdir.Z())
}
Standard_Boolean gp_Ax1::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
gp_XYZ& anXYZLoc = loc.ChangeCoord();
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
&anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
gp_XYZ aDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Direction", aPos, 3,
&aDir.ChangeCoord (1), &aDir.ChangeCoord (2), &aDir.ChangeCoord (3))
SetDirection (aDir);
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -208,7 +208,8 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected:

View File

@@ -122,3 +122,34 @@ void gp_Ax2::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
OCCT_DUMP_VECTOR_CLASS (theOStream, "XDirection", 3, vxdir.X(), vxdir.Y(), vxdir.Z())
OCCT_DUMP_VECTOR_CLASS (theOStream, "YDirection", 3, vydir.X(), vydir.Y(), vydir.Z())
}
Standard_Boolean gp_Ax2::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
gp_XYZ anXYZLoc;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
&anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
SetLocation (anXYZLoc);
gp_XYZ aDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Direction", aPos, 3,
&aDir.ChangeCoord (1), &aDir.ChangeCoord (2), &aDir.ChangeCoord (3))
gp_XYZ aXDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "XDirection", aPos, 3,
&aXDir.ChangeCoord (1), &aXDir.ChangeCoord (2), &aXDir.ChangeCoord (3))
gp_XYZ anYDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "YDirection", aPos, 3,
&anYDir.ChangeCoord (1), &anYDir.ChangeCoord (2), &anYDir.ChangeCoord (3))
axis.SetDirection (gp_Dir (aDir));
vxdir = gp_Dir (aXDir);
vydir = gp_Dir (anYDir);
if (!Direction().IsEqual (aDir, Precision::Confusion()))
return Standard_False;
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -326,6 +326,9 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected:

View File

@@ -115,3 +115,31 @@ void gp_Ax3::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
OCCT_DUMP_VECTOR_CLASS (theOStream, "XDirection", 3, XDirection().X(), XDirection().Y(), XDirection().Z())
OCCT_DUMP_VECTOR_CLASS (theOStream, "YDirection", 3, YDirection().X(), YDirection().Y(), YDirection().Z())
}
Standard_Boolean gp_Ax3::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
gp_XYZ anXYZLoc;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
&anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
SetLocation (anXYZLoc);
gp_XYZ aDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Direction", aPos, 3,
&aDir.ChangeCoord (1), &aDir.ChangeCoord (2), &aDir.ChangeCoord (3))
gp_XYZ aXDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "XDirection", aPos, 3,
&aXDir.ChangeCoord (1), &aXDir.ChangeCoord (2), &aXDir.ChangeCoord (3))
gp_XYZ anYDir;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "YDirection", aPos, 3,
&anYDir.ChangeCoord (1), &anYDir.ChangeCoord (2), &anYDir.ChangeCoord (3))
axis.SetDirection (gp_Dir (aDir));
vxdir = gp_Dir (aXDir);
vydir = gp_Dir (anYDir);
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -293,7 +293,8 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected:

View File

@@ -144,3 +144,13 @@ void gp_Dir::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
{
OCCT_DUMP_VECTOR_CLASS (theOStream, "gp_Dir", 3, coord.X(), coord.Y(), coord.Z())
}
Standard_Boolean gp_Dir::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "gp_Dir", aPos, 3, &coord.ChangeCoord (1), &coord.ChangeCoord (2), &coord.ChangeCoord (3))
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -266,6 +266,8 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected:

View File

@@ -90,3 +90,13 @@ void gp_Pnt::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
{
OCCT_DUMP_VECTOR_CLASS (theOStream, "gp_Pnt", 3, coord.X(), coord.Y(), coord.Z())
}
Standard_Boolean gp_Pnt::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "gp_Pnt", aPos, 3, &coord.ChangeCoord (1), &coord.ChangeCoord (2), &coord.ChangeCoord (3))
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -177,7 +177,8 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected:

View File

@@ -915,3 +915,39 @@ void gp_Trsf::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, shape)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, scale)
}
//=======================================================================
//function : InitFromJson
//purpose :
//=======================================================================
Standard_Boolean gp_Trsf::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
gp_XYZ anXYZLoc;
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
&anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
SetTranslation (anXYZLoc);
Standard_Real mymatrix[3][3];
OCCT_INIT_VECTOR_CLASS (aStreamStr, "Matrix", aPos, 9, &mymatrix[0][0], &mymatrix[0][1], &mymatrix[0][2],
&mymatrix[1][0], &mymatrix[1][1], &mymatrix[1][2],
&mymatrix[2][0], &mymatrix[2][1], &mymatrix[2][2])
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
matrix.SetValue (i + 1, j + 1, mymatrix[i][j]);
}
}
Standard_Real ashape;
OCCT_INIT_FIELD_VALUE_INTEGER (aStreamStr, aPos, ashape);
shape = (gp_TrsfForm)((Standard_Integer)ashape);
OCCT_INIT_FIELD_VALUE_REAL (aStreamStr, aPos, scale);
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -25,6 +25,7 @@
#include <Standard_Integer.hxx>
#include <Standard_Handle.hxx>
#include <Standard_OStream.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Real.hxx>
class Standard_ConstructionError;
@@ -354,6 +355,9 @@ void operator *= (const gp_Trsf& T)
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
friend class gp_GTrsf;
protected:

View File

@@ -42,3 +42,17 @@ void gp_XYZ::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
{
OCCT_DUMP_VECTOR_CLASS (theOStream, "gp_XYZ", 3, x, y, z)
}
//=======================================================================
//function : InitFromJson
//purpose :
//=======================================================================
Standard_Boolean gp_XYZ::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
{
Standard_Integer aPos = theStreamPos;
OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "gp_XYZ", aPos, 3, &x, &y, &z)
theStreamPos = aPos;
return Standard_True;
}

View File

@@ -24,6 +24,7 @@
#include <Standard_Boolean.hxx>
#include <Standard_OStream.hxx>
#include <Standard_SStream.hxx>
class Standard_ConstructionError;
class Standard_OutOfRange;
@@ -330,6 +331,9 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
protected: