]> OCCT Git - occt-copy.git/commitdiff
0031326: Foundation Classes - Init from Json for base OCCT classes
authornds <nds@opencascade.com>
Mon, 7 Sep 2020 21:16:32 +0000 (00:16 +0300)
committernds <nds@opencascade.com>
Thu, 19 Nov 2020 14:10:58 +0000 (17:10 +0300)
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.

(cherry picked from commit 6b63dc83c3b18514fa808afb1c069cd82f895d44)

# Conflicts:
# src/Standard/Standard_Dump.hxx

33 files changed:
src/BVH/BVH_Box.hxx
src/Bnd/Bnd_Box.cxx
src/Bnd/Bnd_Box.hxx
src/Quantity/Quantity_Color.cxx
src/Quantity/Quantity_Color.hxx
src/Quantity/Quantity_ColorRGBA.cxx
src/Quantity/Quantity_ColorRGBA.hxx
src/Standard/Standard_Dump.cxx
src/Standard/Standard_Dump.hxx
src/gp/gp_Ax1.cxx
src/gp/gp_Ax1.hxx
src/gp/gp_Ax2.cxx
src/gp/gp_Ax2.hxx
src/gp/gp_Ax3.cxx
src/gp/gp_Ax3.hxx
src/gp/gp_Dir.cxx
src/gp/gp_Dir.hxx
src/gp/gp_Pnt.cxx
src/gp/gp_Pnt.hxx
src/gp/gp_Trsf.cxx
src/gp/gp_Trsf.hxx
src/gp/gp_XYZ.cxx
src/gp/gp_XYZ.hxx
tools/Convert/Convert_Tools.cxx
tools/Convert/Convert_Tools.hxx
tools/TreeModel/TreeModel_ItemBase.cxx
tools/TreeModel/TreeModel_ItemBase.hxx
tools/VInspector/VInspector_ItemPresentableObject.cxx
tools/VInspector/VInspector_Window.cxx
tools/View/View_DisplayPreview.cxx
tools/View/View_DisplayPreview.hxx
tools/View/View_Displayer.cxx
tools/View/View_PreviewParameters.cxx

index 06dca01743eff95434137f7011cd99f6d87a9f2d..7441c1611b2e9227ada5e2c499b5aa841a376aa7 100644 (file)
@@ -122,18 +122,65 @@ public:
       OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMinPoint[0])
       OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMinPoint[0])
     }
-    if (n == 2)
+    else if (n == 2)
     {
       OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "MinPoint", n, myMinPoint[0], myMinPoint[1])
       OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "MaxPoint", n, myMaxPoint[0], myMaxPoint[1])
     }
-    if (n == 3)
+    else if (n == 3)
     {
       OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "MinPoint", n, myMinPoint[0], myMinPoint[1], myMinPoint[2])
       OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "MaxPoint", n, myMaxPoint[0], myMaxPoint[1], myMaxPoint[2])
     }
   }
 
+  //! Inits the content of me from the stream
+  Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
+  {
+    Standard_Integer aPos = theStreamPos;
+
+    Standard_Integer anIsInited = 0;
+    TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
+
+    OCCT_INIT_FIELD_VALUE_INTEGER (aStreamStr, aPos, anIsInited);
+    myIsInited = anIsInited != 0;
+
+    int n = Min (N, 3);
+    if (n == 1)
+    {
+      Standard_Real aValue;
+      OCCT_INIT_FIELD_VALUE_REAL (aStreamStr, aPos, aValue);
+      myMinPoint[0] = (T)aValue;
+    }
+    else if (n == 2)
+    {
+      Standard_Real aValue1, aValue2;
+      OCCT_INIT_VECTOR_CLASS (aStreamStr, "MinPoint", aPos, n, &aValue1, &aValue2);
+      myMinPoint[0] = (T)aValue1;
+      myMinPoint[1] = (T)aValue2;
+
+      OCCT_INIT_VECTOR_CLASS (aStreamStr, "MaxPoint", aPos, n, &aValue1, &aValue2);
+      myMaxPoint[0] = (T)aValue1;
+      myMaxPoint[1] = (T)aValue2;
+    }
+    else if (n == 3)
+    {
+      Standard_Real aValue1, aValue2, aValue3;
+      OCCT_INIT_VECTOR_CLASS (aStreamStr, "MinPoint", aPos, n, &aValue1, &aValue2, &aValue3);
+      myMinPoint[0] = (T)aValue1;
+      myMinPoint[1] = (T)aValue2;
+      myMinPoint[2] = (T)aValue3;
+
+      OCCT_INIT_VECTOR_CLASS (aStreamStr, "MaxPoint", aPos, n, &aValue1, &aValue2, &aValue3);
+      myMaxPoint[0] = (T)aValue1;
+      myMaxPoint[1] = (T)aValue2;
+      myMaxPoint[2] = (T)aValue3;
+    }
+
+    theStreamPos = aPos;
+    return Standard_True;
+  }
+
 public:
 
   //! Checks if the Box is out of the other box.
index cb4fbedad97f770a8fae69aa2c904d7a3b3183dd..0b09e26cf32983da50463753db8308e2c4141d84 100644 (file)
@@ -983,3 +983,22 @@ void Bnd_Box::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, Gap)
   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, Flags)
 }
+
+//=======================================================================
+//function : InitFromJson
+//purpose  : 
+//=======================================================================
+Standard_Boolean Bnd_Box::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
+{
+  Standard_Integer aPos = theStreamPos;
+
+  TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
+  OCCT_INIT_VECTOR_CLASS (aStreamStr, "CornerMin", aPos, 3, &Xmin, &Ymin, &Zmin)
+  OCCT_INIT_VECTOR_CLASS (aStreamStr, "CornerMax", aPos, 3, &Xmax, &Ymax, &Zmax)
+
+  OCCT_INIT_FIELD_VALUE_REAL (aStreamStr, aPos, Gap);
+  OCCT_INIT_FIELD_VALUE_INTEGER (aStreamStr, aPos, Flags);
+
+  theStreamPos = aPos;
+  return Standard_True;
+}
index c3ff8a32bb93d0f0aa152f60e3210f0a217291d3..fda5b491ffab7147b1a2bb5ab3ae5cd453af55b8 100644 (file)
@@ -305,6 +305,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:
 
   //! Bit flags.
index da131b8d21f7bc225baca5788c634a438598daa0..d0d58245eb7de7d4ccff342de95ba9f2a1c8e26b 100644 (file)
@@ -3934,3 +3934,17 @@ void Quantity_Color::DumpJson (Standard_OStream& theOStream, Standard_Integer) c
 {
   OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "RGB", 3, MyRed, MyGreen, MyBlue)
 }
+
+//=======================================================================
+//function : InitFromJson
+//purpose  : 
+//=======================================================================
+Standard_Boolean Quantity_Color::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
+{
+  Standard_Integer aPos = theStreamPos;
+  Standard_Real  aRed, aGreen, aBlue;
+  OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "RGB", aPos, 3, &aRed, &aGreen, &aBlue)
+
+  SetValues ((Standard_ShortReal)aRed, (Standard_ShortReal)aGreen, (Standard_ShortReal)aBlue, Quantity_TOC_RGB);
+  return Standard_True;
+}
index 307ade37e988de12be29d1a1172d6f90576e4244..5262e3f2350b01cd2974fc229d130860793b668c 100644 (file)
@@ -267,6 +267,9 @@ Standard_Boolean operator == (const Quantity_Color& Other) const
   //! 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);
+
 private:
 
   //! Converts HLS components into RGB ones.
index 422794053089c4ff4ee45fe47d4ee42ccf0056d3..2e3ab3138fdb6ed078df370f92f1985e48a0ea64 100644 (file)
@@ -208,3 +208,18 @@ void Quantity_ColorRGBA::DumpJson (Standard_OStream& theOStream, Standard_Intege
 {
   OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "RGBA", 4, myRgb.Red(), myRgb.Green(), myRgb.Blue(), myAlpha)
 }
+
+//=======================================================================
+//function : InitFromJson
+//purpose  : 
+//=======================================================================
+Standard_Boolean Quantity_ColorRGBA::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
+{
+  Standard_Integer aPos = theStreamPos;
+
+  Standard_Real aRed, aGreen, aBlue, anAlpha;
+  OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "RGBA", aPos, 4, &aRed, &aGreen, &aBlue, &anAlpha)
+
+  SetValues ((Standard_ShortReal)aRed, (Standard_ShortReal)aGreen, (Standard_ShortReal)aBlue, (Standard_ShortReal)anAlpha);
+  return Standard_True;
+}
index 34b4584f335a220c56bc7f406bed8dde5b5f578b..a3d7232207ac4534185633dc683abc5ef28b2845 100644 (file)
@@ -124,6 +124,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);
+
 private:
 
   static void myTestSize3() { Standard_STATIC_ASSERT (sizeof(float) * 3 == sizeof(Quantity_Color)); }
index f6a2fa46212d5ab3246961318d5a7ed994141d88..6da4d7ee7ffbb75a60b816cda4d01357c5ffd572 100644 (file)
@@ -74,6 +74,135 @@ void Standard_Dump::DumpRealValues (Standard_OStream& theOStream, int theCount,
   va_end(vl);
 }
 
+//=======================================================================
+//function : ProcessStreamName
+//purpose  : 
+//=======================================================================
+Standard_Boolean Standard_Dump::ProcessStreamName (const TCollection_AsciiString& theStreamStr,
+                                                   const TCollection_AsciiString& theName,
+                                                   Standard_Integer& theStreamPos)
+{
+  if (theStreamStr.IsEmpty())
+    return Standard_False;
+
+  if (theStreamStr.Length () < theStreamPos)
+    return Standard_False;
+
+  TCollection_AsciiString aSubText = theStreamStr.SubString (theStreamPos, theStreamStr.Length());
+  if (aSubText.StartsWith (JsonKeyToString (Standard_JsonKey_SeparatorValueToValue)))
+  {
+    theStreamPos += JsonKeyLength (Standard_JsonKey_SeparatorValueToValue);
+    aSubText = theStreamStr.SubString (theStreamPos, theStreamStr.Length());
+  }
+  TCollection_AsciiString aKeyName = TCollection_AsciiString (JsonKeyToString (Standard_JsonKey_Quote))
+    + theName
+    + TCollection_AsciiString (JsonKeyToString (Standard_JsonKey_Quote))
+    + JsonKeyToString (Standard_JsonKey_SeparatorKeyToValue);
+  Standard_Boolean aResult = aSubText.StartsWith (aKeyName);
+  if (aResult)
+    theStreamPos += aKeyName.Length();
+
+  return aResult;
+}
+
+//=======================================================================
+//function : ProcessFieldName
+//purpose  : 
+//=======================================================================
+Standard_Boolean Standard_Dump::ProcessFieldName (const TCollection_AsciiString& theStreamStr,
+                                                  const TCollection_AsciiString& theName,
+                                                  Standard_Integer& theStreamPos)
+{
+  if (theStreamStr.IsEmpty())
+    return Standard_False;
+
+  TCollection_AsciiString aSubText = theStreamStr.SubString (theStreamPos, theStreamStr.Length());
+  if (aSubText.StartsWith (JsonKeyToString (Standard_JsonKey_SeparatorValueToValue)))
+  {
+    theStreamPos += JsonKeyLength (Standard_JsonKey_SeparatorValueToValue);
+    aSubText = theStreamStr.SubString (theStreamPos, theStreamStr.Length());
+  }
+
+  TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (theName.ToCString());
+  TCollection_AsciiString aKeyName = TCollection_AsciiString (JsonKeyToString (Standard_JsonKey_Quote))
+    + aName
+    + TCollection_AsciiString (JsonKeyToString (Standard_JsonKey_Quote))
+    + JsonKeyToString (Standard_JsonKey_SeparatorKeyToValue);
+
+  Standard_Boolean aResult = aSubText.StartsWith (aKeyName);
+  if (aResult)
+    theStreamPos += aKeyName.Length();
+
+  return aResult;
+}
+
+//=======================================================================
+//function : InitRealValues
+//purpose  : 
+//=======================================================================
+Standard_Boolean Standard_Dump::InitRealValues (const TCollection_AsciiString& theStreamStr,
+                                                Standard_Integer& theStreamPos,
+                                                int theCount, ...)
+{
+  Standard_Integer aStreamPos = theStreamPos + JsonKeyLength (Standard_JsonKey_OpenContainer);
+
+  TCollection_AsciiString aSubText = theStreamStr.SubString (aStreamPos, theStreamStr.Length());
+
+  va_list  vl;
+  va_start(vl, theCount);
+  aStreamPos = 1;
+  Standard_Integer aClosePos = aSubText.Location (JsonKeyToString (Standard_JsonKey_CloseContainer), aStreamPos, aSubText.Length());
+  for(int i = 0; i < theCount; ++i)
+  {
+    Standard_Integer aNextPos = (i < theCount-1) ? aSubText.Location (JsonKeyToString (Standard_JsonKey_SeparatorValueToValue), aStreamPos, aSubText.Length())
+      : aClosePos;
+
+    TCollection_AsciiString aValueText = aSubText.SubString (aStreamPos, aNextPos - 1);
+
+    if (!aValueText.IsRealValue())
+      return Standard_False;
+
+    Standard_Real aValue = aValueText.RealValue();
+    *(va_arg(vl, Standard_Real*)) = aValue;
+
+    aStreamPos = aNextPos + JsonKeyLength (Standard_JsonKey_SeparatorValueToValue);
+  }
+  va_end(vl);
+  aClosePos = theStreamStr.Location (JsonKeyToString (Standard_JsonKey_CloseContainer), theStreamPos, theStreamStr.Length());
+  theStreamPos = aClosePos + JsonKeyLength (Standard_JsonKey_CloseContainer);
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : InitValue
+//purpose  : 
+//=======================================================================
+Standard_Boolean Standard_Dump::InitValue (const TCollection_AsciiString& theStreamStr,
+                                           Standard_Integer& theStreamPos,
+                                           TCollection_AsciiString& theValue)
+{
+  Standard_Integer aStreamPos = theStreamPos;
+
+  TCollection_AsciiString aSubText = theStreamStr.SubString (aStreamPos, theStreamStr.Length());
+
+  aStreamPos = 1;
+  Standard_Integer aNextPos = aSubText.Location (JsonKeyToString (Standard_JsonKey_SeparatorValueToValue), aStreamPos, aSubText.Length());
+  Standard_JsonKey aNextKey = Standard_JsonKey_SeparatorValueToValue;
+
+  Standard_Integer aCloseChildPos = aSubText.Location (JsonKeyToString (Standard_JsonKey_CloseChild), aStreamPos, aSubText.Length());
+  Standard_Boolean isUseClosePos = (aNextPos > 0 && aCloseChildPos > 0 && aCloseChildPos < aNextPos) || !aNextPos;
+  if (isUseClosePos)
+  {
+    aNextPos = aCloseChildPos;
+    aNextKey = Standard_JsonKey_CloseChild;
+  }
+
+  theValue = aNextPos ? aSubText.SubString (aStreamPos, aNextPos - 1) : aSubText;
+  theStreamPos = aNextPos ? (theStreamPos + (aNextPos - aStreamPos) + JsonKeyLength (aNextKey)) : theStreamStr.Length();
+  return Standard_True;
+}
+
 // =======================================================================
 // function : GetPointerInfo
 // purpose :
index a026bc8c522649f6b55608eea1ff76e76389eb71..bae73abb570541af032c8b7e6ecfb92be55387f5 100644 (file)
   theOStream << "\"" << aName << "\": " << theField; \
 }
 
+//! @def OCCT_INIT_FIELD_VALUE_REAL
+//! Append vector values into output value: "Name": [value_1, value_2, ...]
+//! This macro is intended to have only one row for dumped object in Json.
+//! It's possible to use it without necessity of OCCT_DUMP_CLASS_BEGIN call, but pay attention that it should be only one row in the object dump.
+#define OCCT_INIT_FIELD_VALUE_REAL(theOStream, theStreamPos, theField) \
+{ \
+  Standard_Integer aStreamPos = theStreamPos; \
+  if (!Standard_Dump::ProcessFieldName (theOStream, #theField, aStreamPos)) \
+    return Standard_False; \
+  TCollection_AsciiString aValueText; \
+  if (!Standard_Dump::InitValue (theOStream, aStreamPos, aValueText) || !aValueText.IsRealValue()) \
+    return Standard_False; \
+  theField = aValueText.RealValue(); \
+  theStreamPos = aStreamPos; \
+}
+
+//! @def OCCT_INIT_FIELD_VALUE_NUMERICAL
+//! Append vector values into output value: "Name": [value_1, value_2, ...]
+//! This macro is intended to have only one row for dumped object in Json.
+//! It's possible to use it without necessity of OCCT_DUMP_CLASS_BEGIN call, but pay attention that it should be only one row in the object dump.
+#define OCCT_INIT_FIELD_VALUE_INTEGER(theOStream, theStreamPos, theField) \
+{ \
+  Standard_Integer aStreamPos = theStreamPos; \
+  if (!Standard_Dump::ProcessFieldName (theOStream, #theField, aStreamPos)) \
+    return Standard_False; \
+  TCollection_AsciiString aValueText; \
+  if (!Standard_Dump::InitValue (theOStream, aStreamPos, aValueText) || !aValueText.IsIntegerValue()) \
+    return Standard_False; \
+  theField = aValueText.IntegerValue(); \
+  theStreamPos = aStreamPos; \
+}
+
 //! @def OCCT_DUMP_FIELD_VALUE_STRING
 //! Append into output value: "Name": "Field"
 #define OCCT_DUMP_FIELD_VALUE_STRING(theOStream, theField) \
   } \
 }
 
+//! @def OCCT_INIT_FIELD_VALUES_DUMPED
+//! Append into output value: "Name": { field dumped values }
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own Dump implementation.
+//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
+//! Depth = -1 is the default value, dump here is unlimited.
+#define OCCT_INIT_FIELD_VALUES_DUMPED(theSStream, theStreamPos, theField) \
+{ \
+  if ((theField) == NULL || !(theField)->InitFromJson (theSStream, theStreamPos)) \
+    return Standard_False; \
+}
+
 //! @def OCCT_DUMP_FIELD_VALUES_DUMPED
 //! Append into output value: "Name": { field dumped values }
 //! It computes Dump of the fields. The expected field is a pointer.
   theOStream << "]"; \
 }
 
+//! @def OCCT_INIT_VECTOR_CLASS
+//! Append vector values into output value: "Name": [value_1, value_2, ...]
+//! This macro is intended to have only one row for dumped object in Json.
+//! It's possible to use it without necessity of OCCT_DUMP_CLASS_BEGIN call, but pay attention that it should be only one row in the object dump.
+#define OCCT_INIT_VECTOR_CLASS(theOStream, theName, theStreamPos, theCount, ...) \
+{ \
+  Standard_Integer aStreamPos = theStreamPos; \
+  if (!Standard_Dump::ProcessStreamName (theOStream, theName, aStreamPos)) \
+    return Standard_False; \
+  if (!Standard_Dump::InitRealValues (theOStream, aStreamPos, theCount, __VA_ARGS__)) \
+    return Standard_False; \
+  theStreamPos = aStreamPos; \
+}
+
 //! Kind of key in Json string
 enum Standard_JsonKey
 {
@@ -309,14 +367,46 @@ public:
 
   //! Unite values in one value using template: "value_1", "value_2", ..., "value_n"
   //! @param theOStream [out] stream to be fill with values
-  //! @param theCount numer of values
+  //! @param theCount   [in]  number of values
   Standard_EXPORT static void DumpCharacterValues (Standard_OStream& theOStream, int theCount, ...);
 
   //! Unite values in one value using template: value_1, value_2, ..., value_n
   //! @param theOStream [out] stream to be fill with values
-  //! @param theCount numer of values
+  //! @param theCount   [in]  number of values
   Standard_EXPORT static void DumpRealValues (Standard_OStream& theOStream, int theCount, ...);
 
+  //! Check whether the parameter name is equal to the name in the stream at position
+  //! @param theSStream   [in]  stream with values
+  //! @param theName      [in]  stream key value
+  //! @param theStreamPos [out] current position in the stream
+  Standard_EXPORT static Standard_Boolean ProcessStreamName (const TCollection_AsciiString& theStreamStr,
+                                                             const TCollection_AsciiString& theName,
+                                                             Standard_Integer& theStreamPos);
+
+  //! Check whether the field name is equal to the name in the stream at position
+  //! @param theSStream   [in]  stream with values
+  //! @param theName      [in]  stream key field value
+  //! @param theStreamPos [out] current position in the stream
+  Standard_EXPORT static Standard_Boolean ProcessFieldName (const TCollection_AsciiString& theStreamStr,
+                                                            const TCollection_AsciiString& theName,
+                                                            Standard_Integer& theStreamPos);
+
+  //! Unite values in one value using template: value_1, value_2, ..., value_n
+  //! @param theSStream   [in]  stream with values
+  //! @param theStreamPos [out] current position in the stream
+  //! @param theCount     [in]  number of values
+  Standard_EXPORT static Standard_Boolean InitRealValues (const TCollection_AsciiString& theStreamStr,
+                                                          Standard_Integer& theStreamPos,
+                                                          int theCount, ...);
+
+  //! Returns real value
+  //! @param theSStream   [in]  stream with values
+  //! @param theStreamPos [out] current position in the stream
+  //! @param theValue     [out] stream value
+  Standard_EXPORT static Standard_Boolean InitValue (const TCollection_AsciiString& theStreamStr,
+                                                     Standard_Integer& theStreamPos,
+                                                     TCollection_AsciiString& theValue);
+
   //! Convert field name into dump text value, removes "&" and "my" prefixes
   //! An example, for field myValue, theName is Value, for &myCLass, the name is Class
   //! @param theField a source value 
index 3ee0231b34f08b33f255e5ba292a661c7615bd7e..19a5cfb286e6e8188c9e7b726ac8e39bdbf6d53c 100644 (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;
+}
index 1b2dcd62bcd3fa291f0eb5a80bf446bff373aec5..382d24e250535df6f98949ed847ce05f1794b3bf 100644 (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:
 
index ba8e7b155d56607e6d149ed3f8cbfdac08de227c..4a1ed084c8c9448bee9777e674c68700685149bb 100644 (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;
+}
index 9aaa10fdd30ba35fdab27947657c8bf10c2a3107..d30a82915769482b801598a37d36903334737422 100644 (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:
index ec5e8b7c4d622c0c175fdbab940b6b1eaaf64601..5e233bf74cb5949fa034064856e106a86afae748 100644 (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;
+}
index 96ccdcf8f0c96089bcfb1c3e26e3bfdba7704202..592483a7b53278eb91a2974af07679737e2e3857 100644 (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:
 
index 0714a34e6bb029279de1ac9e590a416892180d70..3dfb999b2d5be67e42d51b6edc406082f9f93efd 100644 (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;
+}
index 17d11d883b8fefa15503dceafc888c486bffd38c..ca4dba31479900832102418d5d3ec8955b66fb5f 100644 (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:
index 10a9b5d4345e5a3feb44ed985b9899e530fd4d15..8929df71ead4f7619c6e1790d0472d3277e23d28 100644 (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;
+}
index 7799a66bfbee5136ec9f20d8d1f12ea4b2f08204..1332f9b51752a062b847df3a43b910c40d2776d5 100644 (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:
 
index 9a4e299de50089a563d7532f318496f7c70b58fa..e2d6dc19728c6a3e23f2e9c95c3547142f23be9d 100644 (file)
@@ -864,3 +864,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;
+}
index 82c15e91c1dfb91235db521143cd789a0322f2be..29c0f080fc4eab9c3f151c95c61fc2311275de59 100644 (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;
@@ -353,6 +354,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:
index 0599ad950e4d1f031b92b5aca5e124fdcc971541..1c85ef60b7f4aec4e4705fc9a25a7011258f7d69 100644 (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;
+}
+
index e3b49d82eca65d20622cc67880d4c5079fe05b27..99dbb1ce0b90c96d28a9388b20eaeac515e0db30 100644 (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:
 
 
index 47b640738dc9d71c0786ce0eeadb3f5f2e619f77..411fb1fd40333ec98cbfb22ac828073d908406ef 100644 (file)
 #include <inspector/Convert_Tools.hxx>
 #include <inspector/Convert_TransientShape.hxx>
 
+#include <AIS_Plane.hxx>
+#include <AIS_Shape.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepPreviewAPI_MakeBox.hxx>
 #include <BRepTools.hxx>
+#include <gp_XY.hxx>
+#include <Geom_Plane.hxx>
+#include <Prs3d_PlaneAspect.hxx>
+#include <Standard_Dump.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TopoDS_Compound.hxx>
 
 // =======================================================================
 // function : ReadShape
@@ -36,19 +47,214 @@ TopoDS_Shape Convert_Tools::ReadShape (const TCollection_AsciiString& theFileNam
 //function : ConvertStreamToPresentations
 //purpose  :
 //=======================================================================
-void Convert_Tools::ConvertStreamToPresentations (const Standard_SStream&,
-                                                  const Standard_Integer,
-                                                  const Standard_Integer,
-                                                  NCollection_List<Handle(Standard_Transient)>&)
+void Convert_Tools::ConvertStreamToPresentations (const Standard_SStream& theSStream,
+                                                  const Standard_Integer theStartPos,
+                                                  const Standard_Integer /*theLastPos*/,
+                                                  NCollection_List<Handle(Standard_Transient)>& thePresentations)
 {
+  int aStartPos = theStartPos;
+
+  gp_XYZ aPoint;
+  if (aPoint.InitFromJson (theSStream, aStartPos))
+  {
+    thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeVertex (aPoint)));
+    return;
+  }
+
+  gp_Pnt aPnt;
+  if (aPnt.InitFromJson (theSStream, aStartPos))
+  {
+    thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeVertex (aPnt)));
+    return;
+  }
+
+  gp_Dir aDir;
+  if (aDir.InitFromJson (theSStream, aStartPos))
+  {
+    thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeEdge (gp::Origin(), aDir.XYZ())));
+    return;
+  }
+
+  gp_Ax2 anAx2;
+  if (anAx2.InitFromJson (theSStream, aStartPos))
+  {
+    Handle(Geom_Plane) aGeomPlane = new Geom_Plane (gp_Ax3 (anAx2));
+    CreatePresentation (aGeomPlane, thePresentations);
+    return;
+  }
+
+  gp_Ax3 anAx3; // should be after gp_Ax2
+  if (anAx3.InitFromJson (theSStream, aStartPos))
+  {
+    Handle(Geom_Plane) aGeomPlane = new Geom_Plane (anAx3);
+    CreatePresentation (aGeomPlane, thePresentations);
+    return;
+  }
+
+  // should be after gp_Ax3
+  gp_Ax1 anAxis;
+  if (anAxis.InitFromJson (theSStream, aStartPos))
+  {
+    thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeEdge (anAxis.Location(), anAxis.Location().Coord() + anAxis.Direction().XYZ())));
+    return;
+  }
+
+  gp_Trsf aTrsf;
+  if (aTrsf.InitFromJson (theSStream, aStartPos))
+  {
+    CreatePresentation (aTrsf, thePresentations);
+    return;
+  }
+
+  Bnd_Box aBox;
+  if (aBox.InitFromJson (theSStream, aStartPos))
+  {
+    TopoDS_Shape aShape;
+    if (Convert_Tools::CreateShape (aBox, aShape))
+      thePresentations.Append (new Convert_TransientShape (aShape));
+    return;
+  }
+
+  Select3D_BndBox3d aSelectBndBox;
+  if (aSelectBndBox.InitFromJson (theSStream, aStartPos))
+  {
+    TopoDS_Shape aShape;
+
+    gp_Pnt aPntMin = gp_Pnt (aSelectBndBox.CornerMin().x(), aSelectBndBox.CornerMin().y(), aSelectBndBox.CornerMin().z());
+    gp_Pnt aPntMax = gp_Pnt (aSelectBndBox.CornerMax().x(), aSelectBndBox.CornerMax().y(), aSelectBndBox.CornerMax().z());
+    if (CreateBoxShape (aPntMin, aPntMax, aShape))
+      thePresentations.Append (new Convert_TransientShape (aShape));
+    return;
+  }
 }
 
 //=======================================================================
 //function : ConvertStreamToColor
 //purpose  :
 //=======================================================================
-Standard_Boolean Convert_Tools::ConvertStreamToColor (const Standard_SStream&,
-                                                      Quantity_Color&)
+Standard_Boolean Convert_Tools::ConvertStreamToColor (const Standard_SStream& theSStream,
+                                                      Quantity_Color& theColor)
 {
+  Standard_Integer aStartPos = 1;
+  Quantity_ColorRGBA aColorRGBA;
+  if (aColorRGBA.InitFromJson (theSStream, aStartPos))
+  {
+    theColor = aColorRGBA.GetRGB();
+    return Standard_True;
+  }
+
+  Quantity_Color aColor;
+  if (aColor.InitFromJson (theSStream, aStartPos))
+  {
+    theColor = aColor;
+    return Standard_True;
+  }
+
   return Standard_False;
 }
+
+//=======================================================================
+//function : CreateShape
+//purpose  :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateShape (const Bnd_Box& theBoundingBox, TopoDS_Shape& theShape)
+{
+  if (theBoundingBox.IsVoid() || theBoundingBox.IsWhole())
+    return Standard_False;
+
+  Standard_Real aXmin, anYmin, aZmin, aXmax, anYmax, aZmax;
+  theBoundingBox.Get (aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
+
+  gp_Pnt aPntMin = gp_Pnt (aXmin, anYmin, aZmin);
+  gp_Pnt aPntMax = gp_Pnt (aXmax, anYmax, aZmax);
+
+  return CreateBoxShape (aPntMin, aPntMax, theShape);
+}
+
+//=======================================================================
+//function : CreateShape
+//purpose  :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateShape (const Bnd_OBB& theBoundingBox, TopoDS_Shape& theShape)
+{
+  if (theBoundingBox.IsVoid())
+    return Standard_False;
+
+  TColgp_Array1OfPnt anArrPnts(0, 8);
+  theBoundingBox.GetVertex(&anArrPnts(0));
+
+  BRep_Builder aBuilder;
+  TopoDS_Compound aCompound;
+  aBuilder.MakeCompound (aCompound);
+
+  aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(0)), gp_Pnt (anArrPnts.Value(1))));
+  aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(0)), gp_Pnt (anArrPnts.Value(2))));
+  aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(1)), gp_Pnt (anArrPnts.Value(3))));
+  aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(2)), gp_Pnt (anArrPnts.Value(3))));
+
+  theShape = aCompound;
+  return Standard_True;
+}
+
+//=======================================================================
+//function : CreateBoxShape
+//purpose  :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax, TopoDS_Shape& theShape)
+{
+  BRepPreviewAPI_MakeBox aMakeBox;
+  aMakeBox.Init (thePntMin, thePntMax);
+  theShape = aMakeBox.Shape();
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : CreatePresentation
+//purpose  :
+//=======================================================================
+void Convert_Tools::CreatePresentation (const Handle(Geom_Plane)& thePlane,
+                                        NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+  Handle(AIS_Plane) aPlanePrs = new AIS_Plane (thePlane);
+
+  aPlanePrs->Attributes()->SetPlaneAspect (new Prs3d_PlaneAspect());
+  Handle (Prs3d_PlaneAspect) aPlaneAspect = aPlanePrs->Attributes()->PlaneAspect();
+  aPlaneAspect->SetPlaneLength (100, 100);
+  aPlaneAspect->SetDisplayCenterArrow (Standard_True);
+  aPlaneAspect->SetDisplayEdgesArrows (Standard_True);
+  aPlaneAspect->SetArrowsSize (100);
+  aPlaneAspect->SetArrowsLength (100);
+  aPlaneAspect->SetDisplayCenterArrow (Standard_True);
+  aPlaneAspect->SetDisplayEdges (Standard_True);
+
+  aPlanePrs->SetColor (Quantity_NOC_WHITE);
+  aPlanePrs->SetTransparency (0);
+
+  thePresentations.Append (aPlanePrs);
+}
+
+//=======================================================================
+//function : CreatePresentation
+//purpose  :
+//=======================================================================
+void Convert_Tools::CreatePresentation (const gp_Trsf& theTrsf,
+                                        NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+  Bnd_Box aBox (gp_Pnt(), gp_Pnt(10., 10., 10));
+
+  TopoDS_Shape aBoxShape;
+  if (!Convert_Tools::CreateShape (aBox, aBoxShape))
+    return;
+
+  Handle(AIS_Shape) aSourcePrs = new AIS_Shape (aBoxShape);
+  aSourcePrs->SetColor (Quantity_NOC_WHITE);
+  aSourcePrs->SetTransparency (0.5);
+  thePresentations.Append (aSourcePrs);
+
+  Handle(AIS_Shape) aTransformedPrs = new AIS_Shape (aBoxShape);
+  aTransformedPrs->SetColor (Quantity_NOC_TOMATO);
+  aTransformedPrs->SetTransparency (0.5);
+  aTransformedPrs->SetLocalTransformation (theTrsf);
+  thePresentations.Append (aTransformedPrs);
+}
index 3145c77ccee97665597c2c2c5ab1066a52d45b35..728c096c74cc0037f198b61f63198d6010330017 100644 (file)
 #ifndef Convert_Tools_H
 #define Convert_Tools_H
 
+#include <gp_Dir.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Trsf.hxx>
+#include <gp_XYZ.hxx>
+#include <Bnd_Box.hxx>
+#include <Bnd_OBB.hxx>
 #include <NCollection_List.hxx>
 #include <Quantity_Color.hxx>
 #include <Standard.hxx>
 #include <Standard_Macro.hxx>
-#include <Standard_SStream.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <Standard_Dump.hxx>
 #include <TCollection_AsciiString.hxx>
+#include <TopLoc_Location.hxx>
 #include <TopoDS_Shape.hxx> 
+#include <Standard_SStream.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QString>
+#include <QVariant>
+#include <Standard_WarningsRestore.hxx>
+
+class Geom_Plane;
+class Geom_Transformation;
 
 //! \class Convert_Tools
-//! \brief The tool that gives auxiliary methods converting.
+//! \brief The tool that gives auxiliary methods for qt elements manipulation.
 class Convert_Tools
 {
 public:
@@ -49,6 +66,37 @@ public:
   //! \returns true if done
   Standard_EXPORT static Standard_Boolean ConvertStreamToColor (const Standard_SStream& theSStream,
                                                                 Quantity_Color& theColor);
+
+  //! Creates box shape
+  //! \param theBoundingBox box shape parameters
+  //! \return created shape
+  Standard_EXPORT static Standard_Boolean CreateShape (const Bnd_Box& theBoundingBox, TopoDS_Shape& theShape);
+
+  //! Creates box shape
+  //! \param theBoundingBox box shape parameters
+  //! \return created shape
+  Standard_EXPORT static Standard_Boolean CreateShape (const Bnd_OBB& theBoundingBox, TopoDS_Shape& theShape);
+
+  //! Creates box shape
+  //! \param thePntMin minimum point on the bounding box
+  //! \param thePntMax maximum point on the bounding box
+  //! \return created shape
+  Standard_EXPORT static Standard_Boolean CreateBoxShape (const gp_Pnt& thePntMin,
+                                                          const gp_Pnt& thePntMax,
+                                                          TopoDS_Shape& theShape);
+
+  //! Creates presentation AIS_Plane
+  //! \param thePlane source plane
+  //! \param thePresentations container to collect new presentation/s
+  Standard_EXPORT static void CreatePresentation (const Handle(Geom_Plane)& thePlane,
+    NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
+  //! Creates two presentations base on gp_Trsf: box in initial place and transformed box
+  //! \param thePlane source plane
+  //! \param thePresentations container to collect new presentation/s
+  Standard_EXPORT static void CreatePresentation (const gp_Trsf& theTrsf,
+    NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
 };
 
 #endif
index 38ef9b23cafe3040d988e2bba2545bc84aa7cd36..1b23b909cbc3a923cd57195c77f98898d48bc6a7 100644 (file)
@@ -92,6 +92,22 @@ TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, cons
   return anItem;
 }
 
+// =======================================================================
+// function :  Presentations
+// purpose :
+// =======================================================================
+void TreeModel_ItemBase::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+  if (Column() != 0)
+    return;
+
+  const Handle(TreeModel_ItemProperties)& anItemProperties = Properties();
+  if (anItemProperties)
+  {
+    anItemProperties->Presentations (thePresentations);
+  }
+}
+
 // =======================================================================
 // function :  currentItem
 // purpose :
index 99f7d210683d21c666ac7d8e94327e6c52df76f2..4c121f8213b2044c4fd5be22422efc71f7426732 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef TreeModel_ItemBase_H
 #define TreeModel_ItemBase_H
 
+#include <NCollection_List.hxx>
 #include <Standard.hxx>
 #include <Standard_Macro.hxx>
 #include <Standard_Handle.hxx>
@@ -149,6 +150,7 @@ public:
   //! Returns the item properties
   const Handle(TreeModel_ItemProperties)& Properties() const { return myProperties; }
 
+  Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
 protected:
 
   //! \param theParent the parent item
index 135170ea1b674b303003cb39e74c5c139df3d255..9babba37ff720d2acfa48d9f3616c88cb695ca81 100644 (file)
@@ -156,7 +156,7 @@ void VInspector_ItemPresentableObject::Init()
     }
     std::sort (aListOfIOSorted.begin(), aListOfIOSorted.end());
 
-    int aCurrentIndex = 0;
+    int aCurrentIndex = 1; /* Properties item of context*/
     for (std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIOIt = aListOfIOSorted.begin(); anIOIt != aListOfIOSorted.end(); anIOIt++, aCurrentIndex++)
     {
       if (aCurrentIndex != aRowId)
@@ -228,9 +228,10 @@ QString VInspector_ItemPresentableObject::PointerInfo() const
 // =======================================================================
 void VInspector_ItemPresentableObject::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
 {
+  TreeModel_ItemBase::Presentations (thePresentations); 
+
   if (Column() != 0)
     return;
-
   thePresentations.Append (GetInteractiveObject());
 }
 
index 22ed9e50f63d4decff4ffec8054315ba17d1f20a..1991dbe6316682cea6ac2faf7f2c56e06ef80d0b 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <inspector/TreeModel_ColumnType.hxx>
 #include <inspector/TreeModel_ContextMenu.hxx>
-#include <inspector/TreeModel_ItemProperties.hxx>
 #include <inspector/TreeModel_Tools.hxx>
 
 #include <inspector/ViewControl_MessageDialog.hxx>
@@ -392,7 +391,10 @@ void VInspector_Window::SelectedShapes (NCollection_List<Handle(Standard_Transie
     TreeModel_ItemBasePtr anItem = *anItemIt;
     VInspector_ItemBasePtr aVItem = itemDynamicCast<VInspector_ItemBase>(anItem);
     if (!aVItem /*|| aVItem->Row() == 0*/)
+    {
+      anItem->Presentations (theSelPresentations);
       continue;
+    }
 
     TopoDS_Shape aShape = aVItem->GetPresentationShape();
     if (aShape.IsNull())
@@ -595,15 +597,11 @@ void VInspector_Window::onTreeViewSelectionChanged (const QItemSelection&,
     if (!anItemBase)
       continue;
 
-    const Handle(TreeModel_ItemProperties)& anItemProperties = anItemBase->Properties();
-    if (anItemProperties)
-    {
-      anItemProperties->Presentations (aSelPresentations);
-    }
+    anItemBase->Presentations (aSelPresentations);
   }
 
   SelectedShapes (aSelPresentations);
-  displayer()->DisplayPreview()->UpdatePreview (View_DisplayActionType_DisplayId, aSelPresentations, myViewWindow->ViewWidget()->DisplayMode());
+  displayer()->UpdatePreview (View_DisplayActionType_DisplayId, aSelPresentations);
 }
 
 // =======================================================================
index 7e6c55123b0e14b41dfce2f91821c18c33393287..e129416f33ba0e9c1845de546d8985c5f3b1e57e 100644 (file)
@@ -79,12 +79,13 @@ void View_DisplayPreview::SetContext (const Handle(AIS_InteractiveContext)& theC
 // purpose :
 // =======================================================================
 void View_DisplayPreview::UpdatePreview (const View_DisplayActionType,
-                                         const NCollection_List<Handle(Standard_Transient)>& thePresentations,
-                                         int theDisplayMode)
+                                         const NCollection_List<Handle(Standard_Transient)>& thePresentations)
 {
   if (myContext.IsNull())
     return;
 
+  int aPreviewDisplayMode = AIS_Shaded;
+
   // clear previous previews
   for (NCollection_List<Handle(AIS_InteractiveObject)>::Iterator anIterator (myPreviewReadyPresentations); anIterator.More(); anIterator.Next())
   {
@@ -115,7 +116,7 @@ void View_DisplayPreview::UpdatePreview (const View_DisplayActionType,
     Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast (anIterator.Value());
     if (!aPrs.IsNull() && aPrs->GetContext().IsNull()/*is not displayed in another context*/)
     {
-      myContext->Display (aPrs, theDisplayMode, -1/*does not participate in selection*/, Standard_True);
+      myContext->Display (aPrs, aPreviewDisplayMode, -1/*does not participate in selection*/, Standard_True);
       enableGlobalClipping(aPrs, false);
       myPreviewReadyPresentations.Append (aPrs);
     }
@@ -128,7 +129,7 @@ void View_DisplayPreview::UpdatePreview (const View_DisplayActionType,
     myPreviewPresentation->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0));
     myPreviewPresentation->SetAttributes (myPreviewParameters->GetDrawer());
 
-    myContext->Display (myPreviewPresentation, theDisplayMode, -1/*does not participate in selection*/, Standard_True);
+    myContext->Display (myPreviewPresentation, aPreviewDisplayMode, -1/*does not participate in selection*/, Standard_True);
     enableGlobalClipping(myPreviewPresentation, false);
   }
   else
@@ -140,28 +141,3 @@ void View_DisplayPreview::UpdatePreview (const View_DisplayActionType,
     }
   }
 }
-
-// =======================================================================
-// function : SetDisplayMode
-// purpose :
-// =======================================================================
-void View_DisplayPreview::SetDisplayMode (const int theDisplayMode, const bool theToUpdateViewer)
-{
-  if (myContext.IsNull())
-    return;
-
-  if (!myPreviewPresentation.IsNull())
-  {
-     if (myContext == myPreviewPresentation->GetContext())
-       myContext->SetDisplayMode (myPreviewPresentation, theDisplayMode, Standard_False);
-  }
-
-  for (NCollection_List<Handle(AIS_InteractiveObject)>::Iterator aPreviewIt (myPreviewReadyPresentations); aPreviewIt.More(); aPreviewIt.Next())
-  {
-     if (myContext == aPreviewIt.Value()->GetContext())
-       myContext->SetDisplayMode (aPreviewIt.Value(), theDisplayMode, Standard_False);
-  }
-
-  if (theToUpdateViewer)
-    myContext->UpdateCurrentViewer();
-}
index 530bfea2480aace7089051cf4de154fc51f76d47..550e681289a059c3aef94efd6ee7e0e9557eb35e 100644 (file)
@@ -53,12 +53,7 @@ public:
 
   //! Updates visibility of the presentations for the display type
   Standard_EXPORT void UpdatePreview (const View_DisplayActionType theType,
-                                      const NCollection_List<Handle(Standard_Transient)>& thePresentations,
-                                      int theDisplayMode);
-
-  //! Sets display mode for all displayed presentations
-  Standard_EXPORT void SetDisplayMode (const int theDisplayMode,
-                                       const bool theToUpdateViewer = true);
+                                      const NCollection_List<Handle(Standard_Transient)>& thePresentations);
 
   //! Returns true if preview presentation is shown
   Standard_Boolean HasPreview() const { return !myPreviewPresentation.IsNull(); }
index 796b6d256466ae6f2031b384da26836061f144ab..fb868a9c2e94ed8e424421d9f9097683b0599385 100644 (file)
@@ -34,7 +34,7 @@
 // purpose :
 // =======================================================================
 View_Displayer::View_Displayer()
-: myIsKeepPresentations (false), myFitAllActive (false), myDisplayMode (-1)
+: myIsKeepPresentations (false), myFitAllActive (false), myDisplayMode (0)
 {
   myDisplayPreview = new View_DisplayPreview();
 }
@@ -79,8 +79,6 @@ void View_Displayer::SetDisplayMode (const int theDisplayMode,
   for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
     GetContext()->SetDisplayMode (aDisplayedIt.Value(), theDisplayMode, Standard_False);
 
-  myDisplayPreview->SetDisplayMode (theDisplayMode, Standard_False);
-
   if (theToUpdateViewer)
     UpdateViewer();
 }
@@ -270,7 +268,7 @@ bool View_Displayer::IsVisible (const TopoDS_Shape& theShape, const View_Present
 void View_Displayer::UpdatePreview (const View_DisplayActionType theType,
                                     const NCollection_List<Handle(Standard_Transient)>& thePresentations)
 {
-  myDisplayPreview->UpdatePreview (theType, thePresentations, myDisplayMode);
+  myDisplayPreview->UpdatePreview (theType, thePresentations);
   if (!myIsKeepPresentations || myFitAllActive)
     fitAllView();
 }
index 8cc48d06b1f4885f7192323cea3c2eb705d0f003..44e296838443eb89b010f6cffc85b4043e15ea52 100644 (file)
@@ -28,6 +28,7 @@ View_PreviewParameters::View_PreviewParameters()
   myDrawer = new Prs3d_Drawer();
 
   Quantity_Color aColor(Quantity_NOC_TOMATO);
+  Standard_ShortReal aTransparency = 0.8f;
 
   // point parameters
   myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0));
@@ -41,6 +42,10 @@ View_PreviewParameters::View_PreviewParameters()
   myDrawer->ShadingAspect()->SetColor (aColor);
   myDrawer->ShadingAspect()->SetMaterial (aShadingMaterial);
 
+  myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (aTransparency);
+  myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (aTransparency);
+  myDrawer->SetTransparency (aTransparency);
+
   // common parameters
   myDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
 }