From: nds Date: Thu, 6 Jun 2019 05:25:49 +0000 (+0300) Subject: 0030268: Inspectors - improvements in VInspector plugin X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=2cabcf39aa38408f2ae927c1a693e59167f29bb6;p=occt-copy.git 0030268: Inspectors - improvements in VInspector plugin - display BVH information in VInspector (cherry picked from commit ca4acb9b1d8285ca92e6ee5a1f8098bf5b4594ea) --- diff --git a/src/BVH/BVH_Box.hxx b/src/BVH/BVH_Box.hxx index 8210aa39ba..4e7dfc94e7 100644 --- a/src/BVH/BVH_Box.hxx +++ b/src/BVH/BVH_Box.hxx @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -108,6 +109,18 @@ public: //! Returns center of bounding box along the given axis. T Center (const Standard_Integer theAxis) const; + //! Dumps the content of me on the stream . + void Dump (Standard_OStream& OS) const + { + DUMP_VALUES (OS, "BVH_Box", 2); + DUMP_VALUES (OS, "IsValid", IsValid()); + + DUMP_VALUES (OS, "Bnd_Box", BVH::ToBndBox (CornerMin(), CornerMax()).ToString()); + + //DUMP_VALUES (OS, "CornerMin", BVH::ToString (CornerMin())); + //DUMP_VALUES (OS, "CornerMin", BVH::ToString (CornerMax())); + } + protected: BVH_VecNt myMinPoint; //!< Minimum point of bounding box diff --git a/src/BVH/BVH_Tree.hxx b/src/BVH/BVH_Tree.hxx index a223d14b30..a46f717a50 100644 --- a/src/BVH/BVH_Tree.hxx +++ b/src/BVH/BVH_Tree.hxx @@ -18,6 +18,11 @@ #include +#include + +#include +#include + template class BVH_Builder; //! A non-template class for using as base for BVH_TreeBase @@ -27,6 +32,13 @@ class BVH_TreeBaseTransient : public Standard_Transient DEFINE_STANDARD_RTTIEXT(BVH_TreeBaseTransient, Standard_Transient) protected: BVH_TreeBaseTransient() {} + + //! Dumps the content of me on the stream . + virtual void Dump (Standard_OStream& OS) const { (void)OS; } + + //! Dumps the content of the given node on the stream . + virtual void DumpNode (const int theNodeIndex, Standard_OStream& OS) const + { (void)theNodeIndex; (void)OS; } }; //! Stores parameters of bounding volume hierarchy (BVH). @@ -178,6 +190,35 @@ public: //! @name methods for accessing serialized tree data return myMaxPointBuffer; } + //! Dumps the content of me on the stream . + Standard_EXPORT virtual void Dump (Standard_OStream& OS) const Standard_OVERRIDE + { + DUMP_VALUES (OS, "BVH_Tree", 2); + + DUMP_VALUES (OS, "Depth", Depth()); + DUMP_VALUES (OS, "Length", Length()); + + for (Standard_Integer aNodeIdx = 0; aNodeIdx < Length(); ++aNodeIdx) + { + DumpNode (aNodeIdx, OS); + } + } + + //! Dumps the content of the given node on the stream . + Standard_EXPORT virtual void DumpNode (const int theNodeIndex, Standard_OStream& OS) const Standard_OVERRIDE + { + DUMP_VALUES (OS, "BVH_TreeNode", 2); + DUMP_VALUES (OS, "NodeIndex", theNodeIndex); + + DUMP_VALUES (OS, "MinPoint - MaxPoint", BVH::ToBndBox (MinPoint (theNodeIndex), MaxPoint (theNodeIndex)).ToString()); + + DUMP_VALUES (OS, "BegPrimitive", BegPrimitive (theNodeIndex)); + DUMP_VALUES (OS, "EndPrimitive", EndPrimitive (theNodeIndex)); + DUMP_VALUES (OS, "Level", Level (theNodeIndex)); + DUMP_VALUES (OS, "IsOuter", IsOuter (theNodeIndex)); + } + + public: //! @name protected fields //! Array of node data records. diff --git a/src/BVH/BVH_Types.hxx b/src/BVH/BVH_Types.hxx index 6cbf7ae916..fcbc66bca1 100644 --- a/src/BVH/BVH_Types.hxx +++ b/src/BVH/BVH_Types.hxx @@ -21,10 +21,12 @@ #include +#include #include #include #include #include +#include #include // GCC supports shrink function only in C++11 mode @@ -57,6 +59,32 @@ namespace BVH typedef NCollection_Vec3 Type; }; + template Bnd_Box ToBndBox (const T& theType1, const T& theType2) + { + return Bnd_Box (theType1, 0., 0., theType2, 0., 0.); + } + + template Bnd_Box ToBndBox (const NCollection_Vec2& theType1, + const NCollection_Vec2& theType2) + { + return Bnd_Box (theType1.x(), theType1.y(), 0., + theType2.x(), theType2.y(), 0.); + } + + template Bnd_Box ToBndBox (const NCollection_Vec3& theType1, + const NCollection_Vec3& theType2) + { + return Bnd_Box (theType1.x(), theType1.y(), theType1.z(), + theType2.x(), theType2.y(), theType2.z()); + } + + template Bnd_Box ToBndBox (const NCollection_Vec4& theType1, + const NCollection_Vec4& theType2) + { + return Bnd_Box (theType1.x(), theType1.y(), theType1.z(), + theType2.x(), theType2.y(), theType2.z()); + } + template struct VectorType { typedef NCollection_Vec4 Type; diff --git a/src/Bnd/Bnd_Box.cxx b/src/Bnd/Bnd_Box.cxx index 3f9ea999ff..d7e67d141a 100644 --- a/src/Bnd/Bnd_Box.cxx +++ b/src/Bnd/Bnd_Box.cxx @@ -43,6 +43,19 @@ Bnd_Box::Bnd_Box() SetVoid(); } +//======================================================================= +//function : Bnd_Box +//purpose : +//======================================================================= + +Bnd_Box::Bnd_Box (const Standard_Real theXmin, const Standard_Real theYmin, const Standard_Real theZmin, + const Standard_Real theXmax, const Standard_Real theYmax, const Standard_Real theZmax) +: Gap (0.0) +{ + SetVoid(); + Update (theXmin, theYmin, theZmin, theXmax, theYmax, theZmax); +} + //======================================================================= //function : Set //purpose : @@ -957,3 +970,49 @@ void Bnd_Box::Dump () const cout << "\n Gap : " << Gap; cout << "\n"; } + +//======================================================================= +//function : PointsSeparator +//purpose : +//======================================================================= +TCollection_AsciiString PointsSeparator() +{ + return " - "; +} + +//======================================================================= +//function : ToString +//purpose : +//======================================================================= + +TCollection_AsciiString Bnd_Box::ToString() const +{ + return gp_XYZ (Xmin, Ymin, Zmin).ToString() + + PointsSeparator() + + gp_XYZ (Xmax, Ymax, Zmax).ToString(); +} + +//======================================================================= +//function : FromString +//purpose : +//======================================================================= + +Standard_Boolean Bnd_Box::FromString (const TCollection_AsciiString& theValue) +{ + TCollection_AsciiString aCurrentString = theValue; + Standard_Integer aPosition = aCurrentString.Search (PointsSeparator()); + if (aPosition < 0) + return Standard_False; + + TCollection_AsciiString aLeftString = aCurrentString; + TCollection_AsciiString aRightString = aLeftString.Split (aPosition - 1); + aCurrentString = aRightString; + aRightString = aCurrentString.Split (PointsSeparator().Length()); + + gp_XYZ aMinPoint, aMaxPoint; + if (!aMinPoint.FromString (aLeftString) || !aMaxPoint.FromString (aRightString)) + return Standard_False; + + Update (aMinPoint.X(), aMinPoint.Y(), aMinPoint.Z(), aMaxPoint.X(), aMaxPoint.Y(), aMaxPoint.Z()); + return Standard_True; +} diff --git a/src/Bnd/Bnd_Box.hxx b/src/Bnd/Bnd_Box.hxx index 301d9ad72c..268db71f36 100644 --- a/src/Bnd/Bnd_Box.hxx +++ b/src/Bnd/Bnd_Box.hxx @@ -24,6 +24,10 @@ #include #include #include + +#include +#include + class Standard_ConstructionError; class gp_Pnt; class gp_Dir; @@ -69,6 +73,14 @@ public: //! The constructed box is qualified Void. Its gap is null. Standard_EXPORT Bnd_Box(); + //! Creates a bounding box, it contains: + //! - interval [ aXmin,aXmax ] in the "X Direction", + //! - interval [ aYmin,aYmax ] in the "Y Direction", + //! - interval [ aZmin,aZmax ] in the "Z Direction"; + //! The constructed box is qualified Void. Its gap is null. + Standard_EXPORT Bnd_Box (const Standard_Real aXmin, const Standard_Real aYmin, const Standard_Real aZmin, + const Standard_Real aXmax, const Standard_Real aYmax, const Standard_Real aZmax); + //! Sets this bounding box so that it covers the whole of 3D space. //! It is infinitely long in all directions. void SetWhole() { Flags = WholeMask; } @@ -296,6 +308,14 @@ public: && Xmax >= Xmin; } + //! Covers bounding box into string in format: (Xmin, Ymin, Zmin) - (Xmax, Ymax, Zmax) + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const; + + //! Converts text value into parameters if possible, the string format is: (Xmin, Ymin, Zmin) - (Xmax, Ymax, Zmax) + //! \return true if conversion is done + Standard_EXPORT Standard_Boolean FromString (const TCollection_AsciiString& theValue); + protected: //! Bit flags. diff --git a/src/Bnd/Bnd_OBB.cxx b/src/Bnd/Bnd_OBB.cxx index e9b7f36ea8..d0b4382f74 100644 --- a/src/Bnd/Bnd_OBB.cxx +++ b/src/Bnd/Bnd_OBB.cxx @@ -677,3 +677,19 @@ void Bnd_OBB::Add(const Bnd_OBB& theOther) ReBuild(TColgp_Array1OfPnt(aList[0], 0, 15)); } +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +Standard_Boolean Bnd_OBB::Init (const Standard_OStream& OS) +{ + return Standard_False; +} + +// ======================================================================= +// function : Dump +// purpose : +// ======================================================================= +void Bnd_OBB::Dump (Standard_OStream& OS) const +{ +} diff --git a/src/Bnd/Bnd_OBB.hxx b/src/Bnd/Bnd_OBB.hxx index d40d22ca93..065e67d959 100644 --- a/src/Bnd/Bnd_OBB.hxx +++ b/src/Bnd/Bnd_OBB.hxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -276,6 +277,12 @@ public: //! (which it was created from) and theP. Standard_EXPORT void Add(const gp_Pnt& theP); + //! Dumps the content of me on the stream . + Standard_EXPORT Standard_Boolean Init (const Standard_OStream& OS); + + //! Dumps the content of me on the stream . + Standard_EXPORT void Dump (Standard_OStream& OS) const; + protected: void ProcessOnePoint(const gp_Pnt& theP) diff --git a/src/Bnd/Bnd_Range.cxx b/src/Bnd/Bnd_Range.cxx index 63d0961343..6edacda768 100644 --- a/src/Bnd/Bnd_Range.cxx +++ b/src/Bnd/Bnd_Range.cxx @@ -174,4 +174,13 @@ void Bnd_Range::Split(const Standard_Real theVal, { theList.Append(Bnd_Range(aValPrev, myLast)); } -} \ No newline at end of file +} + +//======================================================================= +//function : ToString +//purpose : +//======================================================================= +TCollection_AsciiString Bnd_Range::ToString() const +{ + return TCollection_AsciiString ("[") + myFirst + ", " + myLast + "]"; +} diff --git a/src/Bnd/Bnd_Range.hxx b/src/Bnd/Bnd_Range.hxx index 0c006d27d9..a478e2f0a2 100644 --- a/src/Bnd/Bnd_Range.hxx +++ b/src/Bnd/Bnd_Range.hxx @@ -18,6 +18,7 @@ #include #include +#include #include @@ -256,6 +257,10 @@ public: return ((myFirst == theOther.myFirst) && (myLast == theOther.myLast)); } + //! Covers point into string in format: [myFirst, myLast] + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const; + private: Standard_Real myFirst; //!< Start of range diff --git a/src/Message/Message.cxx b/src/Message/Message.cxx index fe7d02c180..c04816e92c 100644 --- a/src/Message/Message.cxx +++ b/src/Message/Message.cxx @@ -125,3 +125,228 @@ TCollection_AsciiString Message::PointerToString (const void* thePointer, const } return aPtrStr.str().c_str(); } + +// ======================================================================= +// function : StrVectorToString +// purpose : +// ======================================================================= +TCollection_AsciiString Message::StrVectorToString + (const NCollection_Vector& theValues) +{ + TCollection_AsciiString aValue; + for (NCollection_Vector::Iterator aValuesIt (theValues); aValuesIt.More(); aValuesIt.Next()) + { + aValue += aValuesIt.Value(); + if (aValuesIt.More()) + aValue += VectorSeparator(); + } + return aValue; +} + +// ======================================================================= +// function : StrVectorFromString +// purpose : +// ======================================================================= +Standard_Boolean Message::StrVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + while (!aCurrentString.IsEmpty()) + { + Standard_Integer aPosition = aCurrentString.Search (", "); + aValueString = aCurrentString; + if (aPosition > 0) + aCurrentString = aValueString.Split (aPosition - 1); + theValues.Append (aValueString.RealValue()); + if (aPosition > 0) + aCurrentString = aCurrentString.Split (2); + } + return Standard_True; +} + +// ======================================================================= +// function : RealVectorToString +// purpose : +// ======================================================================= +TCollection_AsciiString Message::RealVectorToString + (const NCollection_Vector& theValues) +{ + TCollection_AsciiString aValue = ("("); + + for (NCollection_Vector::Iterator aValuesIt (theValues); aValuesIt.More(); aValuesIt.Next()) + { + aValue += aValuesIt.Value(); + if (aValuesIt.More()) + aValue += VectorSeparator(); + } + aValue += ")"; + + return aValue; +} + +// ======================================================================= +// function : RealVectorFromString +// purpose : +// ======================================================================= +Standard_Boolean Message::RealVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + Standard_Integer aPosition = aCurrentString.Search ("("); + if (aPosition != 1) + return Standard_False; + aCurrentString = aCurrentString.Split (aPosition); + + aPosition = aCurrentString.Search (")"); + if (aPosition != 1) + return Standard_False; + aValueString = aCurrentString.Split (aPosition); + + + while (!aCurrentString.IsEmpty()) + { + // x value + aPosition = aCurrentString.Search (", "); + aValueString = aCurrentString; + if (aPosition > 0) + aCurrentString = aValueString.Split (aPosition - 1); + theValues.Append (aValueString.RealValue()); + if (aPosition > 0) + aCurrentString = aCurrentString.Split (2); + } + return Standard_True; +} + +// ======================================================================= +// function : CoordVectorToString +// purpose : +// ======================================================================= +TCollection_AsciiString Message::CoordVectorToString + (const NCollection_Vector& theValues) +{ + TCollection_AsciiString aValue = ("("); + aValue += RealVectorToString (theValues); + aValue += ")"; + + return aValue; +} + +// ======================================================================= +// function : CoordVectorFromString +// purpose : +// ======================================================================= +Standard_Boolean Message::CoordVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + Standard_Integer aPosition = aCurrentString.Search ("("); + if (aPosition != 1) + return Standard_False; + aCurrentString = aCurrentString.Split (aPosition); + + aPosition = aCurrentString.Search (")"); + if (aPosition != 1) + return Standard_False; + aValueString = aCurrentString.Split (aPosition); + + return RealVectorFromString (aCurrentString, theValues); +} + +// ======================================================================= +// function : ColorVectorToString +// purpose : +// ======================================================================= +TCollection_AsciiString Message::ColorVectorToString + (const NCollection_Vector& theValues) +{ + TCollection_AsciiString aValue = ("["); + aValue += RealVectorToString (theValues); + aValue += "]"; + + return aValue; +} + +// ======================================================================= +// function : ColorVectorFromString +// purpose : +// ======================================================================= +Standard_Boolean Message::ColorVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + Standard_Integer aPosition = aCurrentString.Search ("["); + if (aPosition != 1) + return Standard_False; + aCurrentString = aCurrentString.Split (aPosition); + + aPosition = aCurrentString.Search ("]"); + if (aPosition != 1) + return Standard_False; + aValueString = aCurrentString.Split (aPosition); + + return RealVectorFromString (aCurrentString, theValues); +} + +// ======================================================================= +// function : ConvertStream +// purpose : +// ======================================================================= +void Message::ConvertStream (const Standard_SStream& theStream, + Standard_Integer& theColumnCount, + NCollection_Vector& theValues) +{ + TCollection_AsciiString aStream (theStream.str().c_str()); + Standard_Character aSeparator = Message::DumpSeparator(); + Standard_Integer aColumnCount = 0; + + TCollection_AsciiString aCurrentString = aStream; + Standard_Integer aPosition = aCurrentString.Search (aSeparator); + if (aPosition >= 1) + { + TCollection_AsciiString aTailString = aCurrentString.Split (aPosition); + Standard_Boolean aClassNameFound = Standard_False; + while (!aCurrentString.IsEmpty()) + { + TCollection_AsciiString aValueString = aCurrentString; + aPosition = aValueString.Search (aSeparator); + if (aPosition < 0 ) + break; + aCurrentString = aValueString.Split (aPosition - 1); + + if (!aColumnCount) + { + if (!aClassNameFound) + aClassNameFound = Standard_True; + else + { + if (!aValueString.IsIntegerValue()) + break; // not correct Dump, in correct the first value is number of property columns + aColumnCount = aValueString.IntegerValue(); + } + } + else + theValues.Append (aValueString); + + if (aTailString.IsEmpty()) + break; + aCurrentString = aTailString; + aPosition = aCurrentString.Search (aSeparator); + if (aPosition < 0 ) + { + aCurrentString = aTailString; + aTailString = TCollection_AsciiString(); + } + else + aTailString = aCurrentString.Split (aPosition); + } + } + theColumnCount = aColumnCount; +} diff --git a/src/Message/Message.hxx b/src/Message/Message.hxx index 96feb8de0d..7f9c44a5ab 100644 --- a/src/Message/Message.hxx +++ b/src/Message/Message.hxx @@ -18,6 +18,7 @@ #define _Message_HeaderFile #include +#include #include #include @@ -25,8 +26,9 @@ #include #include +#include + class Message_Messenger; -class TCollection_AsciiString; class Message_Msg; class Message_MsgFile; class Message_Messenger; @@ -86,6 +88,9 @@ public: //! Returns separator symbol of Dump information static Standard_Character DumpSeparator() { return '\\'; } + //! Returns separator symbol of values vector union + static TCollection_AsciiString VectorSeparator() { return " ,"; } + //! Convert handle pointer to string value //! \param thePointer a pointer //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped @@ -99,6 +104,65 @@ public: //! \return the string value Standard_EXPORT static TCollection_AsciiString PointerToString (const void* thePointer, const bool isShortInfo = true); + //! Convert vector of real values to string, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static TCollection_AsciiString StrVectorToString + (const NCollection_Vector& theValues); + + //! Convert string to vector of real values, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static Standard_Boolean StrVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues); + + //! Convert vector of real values to string, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static TCollection_AsciiString RealVectorToString + (const NCollection_Vector& theValues); + + //! Convert string to vector of real values, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static Standard_Boolean RealVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues); + + //! Convert vector of real values to string, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static TCollection_AsciiString CoordVectorToString + (const NCollection_Vector& theValues); + + //! Convert string to vector of real values, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static Standard_Boolean CoordVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues); + + //! Convert vector of real values to string, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static TCollection_AsciiString ColorVectorToString + (const NCollection_Vector& theValues); + + //! Convert string to vector of real values, separator is vector separator + //! \param thePointer a container of real values + //! \return the string value + Standard_EXPORT static Standard_Boolean ColorVectorFromString + (const TCollection_AsciiString& theValue, + NCollection_Vector& theValues); + + //! Converts stream to vector of values and column count + //! \param theStream stream value + //! \param theColumnCount [out] number of columns + //! \param theValues [out] container of split values + static Standard_EXPORT void ConvertStream (const Standard_SStream& theStream, + Standard_Integer& theColumnCount, + NCollection_Vector& theValues); protected: diff --git a/src/Message/Message_Alerts.hxx b/src/Message/Message_Alerts.hxx index 267cc8c8e1..d1789025b2 100644 --- a/src/Message/Message_Alerts.hxx +++ b/src/Message/Message_Alerts.hxx @@ -23,6 +23,9 @@ #include #include +#include +#include + static Handle(Message_Alert) OCCT_Message_Alert; #define MESSAGE_INFO(Name, Description, PerfMeter, ParentAlert) \ @@ -70,5 +73,30 @@ static Handle(Message_Alert) OCCT_Message_Alert; OS << Value1 << Message::DumpSeparator() << Value2 << Message::DumpSeparator(); \ } +#define DUMP_VEC_COLOR(Values, Value) \ + { \ + Value = Message::ColorVectorToString (aValues); \ + } + +#define DUMP_VEC_COLOR_SPLIT(Value, Values) \ + { \ + Message::ColorVectorFromString (Value, Values); \ + } + +#define DUMP_VEC_COORD(Values, Value) \ + { \ + Value = Message::CoordVectorToString (aValues); \ + } + +#define DUMP_VEC_COORD_SPLIT(Value, Values) \ + { \ + Message::CoordVectorFromString (Value, Values); \ + } + + +#define DUMP_VALUES_SPLIT(OS, ColumnCount, Values) \ + { \ + Message::ConvertStream (OS, aColumnCount, aValues); \ + } #endif // _Message_Alerts_HeaderFile diff --git a/src/Message/Message_AttributeVectorOfValues.cxx b/src/Message/Message_AttributeVectorOfValues.cxx index fcbb2fc9d2..3d389a1f45 100644 --- a/src/Message/Message_AttributeVectorOfValues.cxx +++ b/src/Message/Message_AttributeVectorOfValues.cxx @@ -40,7 +40,6 @@ Message_AttributeVectorOfValues::Message_AttributeVectorOfValues (const Standard if (aPosition >= 1) { TCollection_AsciiString aTailString = aCurrentString.Split (aPosition); - Standard_Integer aRow = 0; Standard_Boolean aClassNameFound = Standard_False; while (!aCurrentString.IsEmpty()) { diff --git a/src/Quantity/Quantity_Color.cxx b/src/Quantity/Quantity_Color.cxx index 3c056ff8eb..cd711d7954 100644 --- a/src/Quantity/Quantity_Color.cxx +++ b/src/Quantity/Quantity_Color.cxx @@ -15,6 +15,8 @@ #include +#include +#include #include #include #include @@ -3908,3 +3910,33 @@ void call_rgbhls (float r, float g, float b, float& h, float& l, float& s) if (h < 0.0) h += 360.0; } } + +TCollection_AsciiString Quantity_Color::ToString() const +{ + NCollection_Vector aValues; + aValues.Append (MyRed); + aValues.Append (MyGreen); + aValues.Append (MyBlue); + + Standard_SStream OS; + + TCollection_AsciiString aValue; + DUMP_VEC_COLOR(aValues, aValue) + + return aValue; +} + +Standard_Boolean Quantity_Color::FromString (const TCollection_AsciiString& theValue) +{ + NCollection_Vector aValues; + DUMP_VEC_COLOR_SPLIT (theValue, aValues) + + if (aValues.Size() != 3) + return Standard_False; + + MyRed = (Standard_ShortReal)aValues.Value (0); + MyGreen = (Standard_ShortReal)aValues.Value (1); + MyBlue = (Standard_ShortReal)aValues.Value (2); + + return Standard_True; +} diff --git a/src/Quantity/Quantity_Color.hxx b/src/Quantity/Quantity_Color.hxx index a31c38da5d..a32c04a111 100644 --- a/src/Quantity/Quantity_Color.hxx +++ b/src/Quantity/Quantity_Color.hxx @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -240,6 +241,14 @@ Standard_Boolean operator == (const Quantity_Color& Other) const //! Internal test Standard_EXPORT static void Test(); + //! Covers point into string in format: (X, Y, Z) + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const; + + //! Converts text value into parameters if possible, the string format is: (X, Y, Z) + //! \return true if conversion is done + Standard_EXPORT Standard_Boolean FromString (const TCollection_AsciiString& theValue); + private: //! Converts HLS components into RGB ones. diff --git a/src/Quantity/Quantity_ColorRGBA.hxx b/src/Quantity/Quantity_ColorRGBA.hxx index 8f91d9fea3..dddcaa9695 100644 --- a/src/Quantity/Quantity_ColorRGBA.hxx +++ b/src/Quantity/Quantity_ColorRGBA.hxx @@ -14,6 +14,8 @@ #ifndef _Quantity_ColorRGBA_HeaderFile #define _Quantity_ColorRGBA_HeaderFile +#include +#include #include #include @@ -91,6 +93,40 @@ public: //! Two colors are considered to be equal if their distance is no greater than Epsilon(). bool operator== (const Quantity_ColorRGBA& theOther) const { return IsEqual (theOther); } + + //! Covers point into string in format: (X, Y, Z) + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const + { + NCollection_Vector aValues; + aValues.Append (myRgb.Red()); + aValues.Append (myRgb.Green()); + aValues.Append (myRgb.Blue()); + aValues.Append (myAlpha); + + TCollection_AsciiString aValue; + DUMP_VEC_COORD (aValues, aValue); + return aValue; + } + + + //! Converts text value into parameters if possible, the string format is: (X, Y, Z) + //! \return true if conversion is done + Standard_EXPORT Standard_Boolean FromString (const TCollection_AsciiString& theValue) + { + NCollection_Vector aValues; + DUMP_VEC_COORD_SPLIT (theValue, aValues) + + if (aValues.Size() != 3) + return Standard_False; + + myRgb = Quantity_Color (aValues.Value (0), aValues.Value (1), aValues.Value (2), + Quantity_TOC_RGB); + myAlpha = (Standard_ShortReal)aValues.Value (3); + + return Standard_True; + } + private: static void myTestSize3() { Standard_STATIC_ASSERT (sizeof(float) * 3 == sizeof(Quantity_Color)); } diff --git a/src/SelectBasics/SelectBasics_PickResult.hxx b/src/SelectBasics/SelectBasics_PickResult.hxx index 03bcc16a49..4f45c8906d 100644 --- a/src/SelectBasics/SelectBasics_PickResult.hxx +++ b/src/SelectBasics/SelectBasics_PickResult.hxx @@ -17,6 +17,9 @@ #define _SelectBasics_PickResult_HeaderFile #include +#include + +#include #include //! This structure provides unified access to the results of Matches() method in all sensitive entities, @@ -80,6 +83,15 @@ public: //! Set distance to geometry center. void SetDistToGeomCenter (Standard_Real theDistToCenter) { myDistToCenter = theDistToCenter; } + //! Dumps the content of me on the stream . + void Dump (Standard_OStream& OS) const + { + DUMP_VALUES (OS, "SelectBasics_PickResult", 2); + DUMP_VALUES (OS, "myObjPickedPnt", myObjPickedPnt.XYZ().ToString()); + DUMP_VALUES (OS, "myDepth", myDepth); + DUMP_VALUES (OS, "myDistToCenter", myDistToCenter); + } + private: gp_Pnt myObjPickedPnt; //!< User-picked selection point onto object Standard_Real myDepth; //!< Depth to detected point diff --git a/src/SelectMgr/SelectMgr.cxx b/src/SelectMgr/SelectMgr.cxx index 4e5c63bfa2..2c33d07efd 100644 --- a/src/SelectMgr/SelectMgr.cxx +++ b/src/SelectMgr/SelectMgr.cxx @@ -21,6 +21,11 @@ namespace { "FIRST_ACCEPTABLE", "ONLY_TOPMOST" }; + + static Standard_CString SelectMgr_Table_PrintBVHSubset[4] = + { + "3d", "3dPersistent", "2dPersistent", "Nb" + }; } //======================================================================= @@ -52,3 +57,33 @@ Standard_Boolean SelectMgr::PickingStrategyFromString (Standard_CString theTypeS } return Standard_False; } + +//======================================================================= +//function : BVHSubsetToString +//purpose : +//======================================================================= +Standard_CString SelectMgr::BVHSubsetToString (SelectMgr_SelectableObjectSet::BVHSubset theType) +{ + return SelectMgr_Table_PrintBVHSubset[theType]; +} + +//======================================================================= +//function : BVHSubsetFromString +//purpose : +//======================================================================= +Standard_Boolean SelectMgr::BVHSubsetFromString (Standard_CString theTypeString, + SelectMgr_SelectableObjectSet::BVHSubset& theType) +{ + TCollection_AsciiString aName (theTypeString); + aName.UpperCase(); + for (Standard_Integer aTypeIter = 0; aTypeIter <= SelectMgr_SelectableObjectSet::BVHSubsetNb; ++aTypeIter) + { + Standard_CString aTypeName = SelectMgr_Table_PrintBVHSubset[aTypeIter]; + if (aName == aTypeName) + { + theType = SelectMgr_SelectableObjectSet::BVHSubset (aTypeIter); + return Standard_True; + } + } + return Standard_False; +} diff --git a/src/SelectMgr/SelectMgr.hxx b/src/SelectMgr/SelectMgr.hxx index 9b96b59a34..a8cdcb1178 100644 --- a/src/SelectMgr/SelectMgr.hxx +++ b/src/SelectMgr/SelectMgr.hxx @@ -15,6 +15,7 @@ #define _SelectMgr_HeaderFile #include +#include #include #include #include @@ -52,6 +53,30 @@ public: Standard_EXPORT static Standard_Boolean PickingStrategyFromString (const Standard_CString theTypeString, SelectMgr_PickingStrategy& theType); + + + //! Returns the string name for a given orientation type. + //! @param theType orientation type + //! @return string identifier from the list Xpos, Ypos, Zpos and others + Standard_EXPORT static Standard_CString BVHSubsetToString (SelectMgr_SelectableObjectSet::BVHSubset theType); + + //! Returns the orientation type from the given string identifier (using case-insensitive comparison). + //! @param theTypeString string identifier + //! @return orientation type or BVHSubset_3d if string identifier is invalid + static SelectMgr_SelectableObjectSet::BVHSubset BVHSubsetFromString (Standard_CString theTypeString) + { + SelectMgr_SelectableObjectSet::BVHSubset aType = SelectMgr_SelectableObjectSet::BVHSubset_3d; + BVHSubsetFromString (theTypeString, aType); + return aType; + } + + //! Determines the shape type from the given string identifier (using case-insensitive comparison). + //! @param theTypeString string identifier + //! @param theType detected shape type + //! @return TRUE if string identifier is known + Standard_EXPORT static Standard_Boolean BVHSubsetFromString (const Standard_CString theTypeString, + SelectMgr_SelectableObjectSet::BVHSubset& theType); + }; #endif // _SelectMgr_HeaderFile diff --git a/src/SelectMgr/SelectMgr_BaseFrustum.cxx b/src/SelectMgr/SelectMgr_BaseFrustum.cxx index bf9f43a395..a78cceb3e6 100644 --- a/src/SelectMgr/SelectMgr_BaseFrustum.cxx +++ b/src/SelectMgr/SelectMgr_BaseFrustum.cxx @@ -15,6 +15,9 @@ #include +#include +#include + IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient) //======================================================================= @@ -251,3 +254,17 @@ Standard_Boolean SelectMgr_BaseFrustum::IsClipped (const Graphic3d_SequenceOfHCl { return Standard_True; } + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +void SelectMgr_BaseFrustum::Dump(Standard_OStream& OS)const +{ + DUMP_VALUES (OS, "SelectMgr_BaseFrustum", 2); + + DUMP_VALUES (OS, "myPixelTolerance", myPixelTolerance); + DUMP_VALUES (OS, "myIsOrthographic", myIsOrthographic); + DUMP_VALUES (OS, "myBuilder", Message::TransientToString (myBuilder)); + DUMP_VALUES (OS, "myCamera", Message::TransientToString (myCamera)); +} diff --git a/src/SelectMgr/SelectMgr_BaseFrustum.hxx b/src/SelectMgr/SelectMgr_BaseFrustum.hxx index 6e4852ce11..d402ac371b 100644 --- a/src/SelectMgr/SelectMgr_BaseFrustum.hxx +++ b/src/SelectMgr/SelectMgr_BaseFrustum.hxx @@ -35,6 +35,8 @@ #include +#include + //! This class is an interface for different types of selecting frustums, //! defining different selection types, like point, box or polyline //! selection. It contains signatures of functions for detection of @@ -186,6 +188,9 @@ public: return; } + //! Dumps the content of me on the stream . + Standard_EXPORT virtual void Dump (Standard_OStream& OS) const; + DEFINE_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient) protected: diff --git a/src/SelectMgr/SelectMgr_Frustum.hxx b/src/SelectMgr/SelectMgr_Frustum.hxx index d758bb5e9f..54bb7c7da0 100644 --- a/src/SelectMgr/SelectMgr_Frustum.hxx +++ b/src/SelectMgr/SelectMgr_Frustum.hxx @@ -23,6 +23,7 @@ #include #include #include +#include //! This is an internal class containing representation of rectangular selecting frustum, created in case //! of point and box selection, and algorithms for overlap detection between selecting @@ -58,6 +59,9 @@ public: SelectMgr_Frustum() : SelectMgr_BaseFrustum() {}; + //! Dumps the content of me on the stream . + Standard_EXPORT virtual void Dump (Standard_OStream& OS) const Standard_OVERRIDE; + protected: // SAT Tests for different objects diff --git a/src/SelectMgr/SelectMgr_Frustum.lxx b/src/SelectMgr/SelectMgr_Frustum.lxx index b923f01864..9905d15c66 100644 --- a/src/SelectMgr/SelectMgr_Frustum.lxx +++ b/src/SelectMgr/SelectMgr_Frustum.lxx @@ -14,9 +14,13 @@ // commercial license or contractual agreement. #include + +#include #include #include +//IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_Frustum, SelectMgr_BaseFrustum) + // ======================================================================= // function : isSeparated // purpose : Checks if AABB and frustum are separated along the given axis. @@ -461,3 +465,43 @@ Standard_Boolean SelectMgr_Frustum::hasOverlap (const gp_Pnt& thePnt1, return Standard_True; } + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +template +void SelectMgr_Frustum::Dump(Standard_OStream& OS)const +{ + DUMP_VALUES (OS, "SelectMgr_Frustum", 2); + + DUMP_VALUES (OS, "myPlanes", N + 2); + for (int anIndex = 0; anIndex < N + 2; anIndex++) + DUMP_VALUES (OS, anIndex, myPlanes[anIndex].XYZ().ToString()); + + DUMP_VALUES (OS, "myVertices", N * 2); + for (int anIndex = 0; anIndex < N * 2; anIndex++) + DUMP_VALUES (OS, anIndex, myVertices[anIndex].XYZ().ToString()); + + DUMP_VALUES (OS, "myMaxVertsProjections", N + 2); + for (int anIndex = 0; anIndex < N + 2; anIndex++) + DUMP_VALUES (OS, anIndex, myMaxVertsProjections[anIndex]); + + DUMP_VALUES (OS, "myMinVertsProjections", N + 2); + for (int anIndex = 0; anIndex < N + 2; anIndex++) + DUMP_VALUES (OS, anIndex, myMinVertsProjections[anIndex]); + + DUMP_VALUES (OS, "myMaxOrthoVertsProjections", 3); + for (int anIndex = 0; anIndex < 3; anIndex++) + DUMP_VALUES (OS, anIndex, myMaxOrthoVertsProjections[anIndex]); + + DUMP_VALUES (OS, "myMinOrthoVertsProjections", 3); + for (int anIndex = 0; anIndex < 3; anIndex++) + DUMP_VALUES (OS, anIndex, myMinOrthoVertsProjections[anIndex]); + + DUMP_VALUES (OS, "myEdgeDirs", 6); + for (int anIndex = 0; anIndex < 6; anIndex++) + DUMP_VALUES (OS, anIndex, myEdgeDirs[anIndex].XYZ().ToString()); + + SelectMgr_BaseFrustum::Dump (OS); +} diff --git a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx index d972e19f2d..7bcd7d8353 100644 --- a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx +++ b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx @@ -15,9 +15,12 @@ #include #include - +#include +#include #include +IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_RectangularFrustum, SelectMgr_Frustum<4> ) + // ======================================================================= // function : segmentSegmentDistance // purpose : @@ -138,6 +141,8 @@ namespace const Handle(SelectMgr_FrustumBuilder)& theBuilder, gp_Pnt* theVertices, gp_Vec* theEdges) { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::computeFrustum", "", &aPerfMeter, NULL); // LeftTopNear theVertices[0] = theBuilder->ProjectPntOnViewPlane (theMinPnt.X(), theMaxPnt.Y(), @@ -272,6 +277,8 @@ void SelectMgr_RectangularFrustum::cacheVertexProjections (SelectMgr_Rectangular // ======================================================================= void SelectMgr_RectangularFrustum::Build (const gp_Pnt2d &thePoint) { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Build_1", "", &aPerfMeter, NULL); myNearPickedPnt = myBuilder->ProjectPntOnViewPlane (thePoint.X(), thePoint.Y(), 0.0); myFarPickedPnt = myBuilder->ProjectPntOnViewPlane (thePoint.X(), thePoint.Y(), 1.0); myViewRayDir = myFarPickedPnt.XYZ() - myNearPickedPnt.XYZ(); @@ -304,6 +311,8 @@ void SelectMgr_RectangularFrustum::Build (const gp_Pnt2d &thePoint) void SelectMgr_RectangularFrustum::Build (const gp_Pnt2d& theMinPnt, const gp_Pnt2d& theMaxPnt) { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Build_2", "", &aPerfMeter, NULL); myNearPickedPnt = myBuilder->ProjectPntOnViewPlane ((theMinPnt.X() + theMaxPnt.X()) * 0.5, (theMinPnt.Y() + theMaxPnt.Y()) * 0.5, 0.0); @@ -431,6 +440,10 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const SelectMgr_Vec3& t const SelectMgr_Vec3& theBoxMax, Standard_Boolean* theInside) const { + Message_PerfMeter aPerfMeter; + Bnd_Box aBox (theBoxMin.x(), theBoxMin.y(), theBoxMin.z(), + theBoxMax.x(), theBoxMax.y(), theBoxMax.z()); + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_vvb", aBox.ToString(), &aPerfMeter, NULL); return hasOverlap (theBoxMin, theBoxMax, theInside); } @@ -443,6 +456,8 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const SelectMgr_Vec3& t const SelectMgr_Vec3& theBoxMax, SelectBasics_PickResult& thePickResult) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_vv", "", &aPerfMeter, NULL); if (!hasOverlap (theBoxMin, theBoxMax)) return Standard_False; @@ -463,6 +478,8 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const SelectMgr_Vec3& t Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const gp_Pnt& thePnt, SelectBasics_PickResult& thePickResult) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_1p", "", &aPerfMeter, NULL); if (!hasOverlap (thePnt)) return Standard_False; @@ -482,6 +499,8 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const gp_Pnt& thePnt, // ======================================================================= Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const gp_Pnt& thePnt) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_1", "", &aPerfMeter, NULL); return hasOverlap (thePnt); } @@ -493,6 +512,9 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2, SelectBasics_PickResult& thePickResult) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_2", "", &aPerfMeter, NULL); + if (!hasOverlap (thePnt1, thePnt2)) return Standard_False; @@ -512,6 +534,8 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const TColgp_Array1OfPn Select3D_TypeOfSensitivity theSensType, SelectBasics_PickResult& thePickResult) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_n", "", &aPerfMeter, NULL); if (theSensType == Select3D_TOS_BOUNDARY) { Standard_Integer aMatchingSegmentsNb = -1; @@ -562,6 +586,9 @@ Standard_Boolean SelectMgr_RectangularFrustum::Overlaps (const gp_Pnt& thePnt1, Select3D_TypeOfSensitivity theSensType, SelectBasics_PickResult& thePickResult) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::Overlaps_3", "", &aPerfMeter, NULL); + if (theSensType == Select3D_TOS_BOUNDARY) { const gp_Pnt aPntsArrayBuf[4] = { thePnt1, thePnt2, thePnt3, thePnt1 }; @@ -651,6 +678,9 @@ Standard_Real SelectMgr_RectangularFrustum::DistToGeometryCenter (const gp_Pnt& // ======================================================================= gp_Pnt SelectMgr_RectangularFrustum::DetectedPoint (const Standard_Real theDepth) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::DetectedPoint", "", &aPerfMeter, NULL); + return myNearPickedPnt.XYZ() + myViewRayDir.Normalized().XYZ() * theDepth / myScale; } @@ -661,6 +691,9 @@ gp_Pnt SelectMgr_RectangularFrustum::DetectedPoint (const Standard_Real theDepth void SelectMgr_RectangularFrustum::computeClippingRange (const Graphic3d_SequenceOfHClipPlane& thePlanes, SelectMgr_ViewClipRange& theRange) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_RectangularFrustum::computeClippingRange", "", &aPerfMeter, NULL); + Standard_Real aPlaneA, aPlaneB, aPlaneC, aPlaneD; for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes); aPlaneIt.More(); aPlaneIt.Next()) { @@ -746,6 +779,9 @@ void SelectMgr_RectangularFrustum::computeClippingRange (const Graphic3d_Sequenc Standard_Boolean SelectMgr_RectangularFrustum::IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes, const Standard_Real theDepth) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("IsClipped", "", &aPerfMeter, NULL); + SelectMgr_ViewClipRange aRange; computeClippingRange (thePlanes, aRange); return aRange.IsClipped (theDepth); @@ -797,3 +833,23 @@ void SelectMgr_RectangularFrustum::GetPlanes (NCollection_Vector thePlaneEquations.Append (anEquation); } } + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +void SelectMgr_RectangularFrustum::Dump(Standard_OStream& OS)const +{ + DUMP_VALUES (OS, "SelectMgr_RectangularFrustum", 2); + DUMP_VALUES (OS, "myNearPickedPnt", myNearPickedPnt.XYZ().ToString()); + DUMP_VALUES (OS, "myFarPickedPnt", myFarPickedPnt.XYZ().ToString()); + DUMP_VALUES (OS, "myViewRayDir", myViewRayDir.XYZ().ToString()); + DUMP_VALUES (OS, "myMousePos", myMousePos.XY().ToString()); + DUMP_VALUES (OS, "myScale", myScale); + DUMP_VALUES (OS, "myIsViewClipEnabled", myIsViewClipEnabled); + + DUMP_VALUES (OS, "myViewClipRange", ""); + myViewClipRange.Dump (OS); + + SelectMgr_Frustum<4>::Dump (OS); +} diff --git a/src/SelectMgr/SelectMgr_RectangularFrustum.hxx b/src/SelectMgr/SelectMgr_RectangularFrustum.hxx index 1fae9f4f0a..d48132d61c 100644 --- a/src/SelectMgr/SelectMgr_RectangularFrustum.hxx +++ b/src/SelectMgr/SelectMgr_RectangularFrustum.hxx @@ -18,6 +18,7 @@ #include #include +#include //! This class contains representation of rectangular selecting frustum, created in case //! of point and box selection, and algorithms for overlap detection between selecting @@ -137,6 +138,9 @@ public: //! Ax + By + Cz + D = 0) to the given vector Standard_EXPORT virtual void GetPlanes (NCollection_Vector& thePlaneEquations) const Standard_OVERRIDE; + //! Dumps the content of me on the stream . + Standard_EXPORT virtual void Dump (Standard_OStream& OS) const Standard_OVERRIDE; + protected: Standard_EXPORT void segmentSegmentDistance (const gp_Pnt& theSegPnt1, @@ -164,6 +168,9 @@ private: RightTopNear, RightTopFar, RightBottomNear, RightBottomFar }; +public: + DEFINE_STANDARD_RTTIEXT(SelectMgr_RectangularFrustum, SelectMgr_Frustum<4>) + private: gp_Pnt myNearPickedPnt; //!< 3d projection of user-picked selection point onto near view plane diff --git a/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx b/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx index b81e6a067f..c75c8fe300 100644 --- a/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx @@ -19,7 +19,7 @@ #include #include -//#define REPORT_SELECTION_BUILD +#define REPORT_SELECTION_BUILD #ifdef REPORT_SELECTION_BUILD #include #include @@ -360,11 +360,17 @@ void SelectMgr_SelectableObjectSet::UpdateBVH (const Handle(Graphic3d_Camera)& t const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight) { +#ifdef REPORT_SELECTION_BUILD + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("UpdateBVH", "", &aPerfMeter, NULL); +#endif + // ----------------------------------------- // check and update 3D BVH tree if necessary // ----------------------------------------- if (!IsEmpty (BVHSubset_3d) && myIsDirty[BVHSubset_3d]) { + MESSAGE_INFO ("Check and update 3D BVH", "", &aPerfMeter, NULL); // construct adaptor over private fields to provide direct access for the BVH builder BVHBuilderAdaptorRegular anAdaptor (myObjects[BVHSubset_3d], myDisabledZLayers); @@ -386,6 +392,7 @@ void SelectMgr_SelectableObjectSet::UpdateBVH (const Handle(Graphic3d_Camera)& t if (!IsEmpty (BVHSubset_3dPersistent) && (myIsDirty[BVHSubset_3dPersistent] || myLastViewState.IsChanged (theViewState) || isWindowSizeChanged)) { + MESSAGE_INFO ("Check and update 3D persistence BVH tree", "", &aPerfMeter, NULL); // construct adaptor over private fields to provide direct access for the BVH builder BVHBuilderAdaptorPersistent anAdaptor (myObjects[BVHSubset_3dPersistent], myDisabledZLayers, theCamera, theProjectionMat, theWorldViewMat, theViewportWidth, theViewportHeight); @@ -400,6 +407,7 @@ void SelectMgr_SelectableObjectSet::UpdateBVH (const Handle(Graphic3d_Camera)& t if (!IsEmpty (BVHSubset_2dPersistent) && (myIsDirty[BVHSubset_2dPersistent] || myLastViewState.IsProjectionChanged (theViewState) || isWindowSizeChanged)) { + MESSAGE_INFO ("Check and update 2D persistence BVH tree", "", &aPerfMeter, NULL); // construct adaptor over private fields to provide direct access for the BVH builder BVHBuilderAdaptorPersistent anAdaptor (myObjects[BVHSubset_2dPersistent], myDisabledZLayers, theCamera, theProjectionMat, SelectMgr_SelectableObjectSet_THE_IDENTITY_MAT, theViewportWidth, theViewportHeight); diff --git a/src/SelectMgr/SelectMgr_SelectingVolumeManager.cxx b/src/SelectMgr/SelectMgr_SelectingVolumeManager.cxx index 7073a002ba..8d923d0246 100644 --- a/src/SelectMgr/SelectMgr_SelectingVolumeManager.cxx +++ b/src/SelectMgr/SelectMgr_SelectingVolumeManager.cxx @@ -14,6 +14,8 @@ // commercial license or contractual agreement. #include +#include +#include //======================================================================= // function : SelectMgr_SelectingVolumeManager @@ -396,6 +398,9 @@ gp_Pnt SelectMgr_SelectingVolumeManager::DetectedPoint (const Standard_Real theD Standard_Boolean SelectMgr_SelectingVolumeManager::IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes, const Standard_Real& theDepth) const { + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("SelectMgr_SelectingVolumeManager::IsClipped", "", &aPerfMeter, NULL); + if (myActiveSelectionType != Point) return Standard_False; diff --git a/src/SelectMgr/SelectMgr_SelectingVolumeManager.hxx b/src/SelectMgr/SelectMgr_SelectingVolumeManager.hxx index 92715faabe..3cb694e432 100644 --- a/src/SelectMgr/SelectMgr_SelectingVolumeManager.hxx +++ b/src/SelectMgr/SelectMgr_SelectingVolumeManager.hxx @@ -206,6 +206,19 @@ public: return mySelectingVolumes[myActiveSelectionType / 2]; } + //! Returns active selecting volume that was built during last + //! run of OCCT selection mechanism + Handle(SelectMgr_BaseFrustum) GetVolume (const SelectionType& theType) const + { + switch (theType) + { + case Point: + case Box: return mySelectingVolumes[Frustum]; + case Polyline: return mySelectingVolumes[FrustumSet]; + default: return NULL; + } + } + //! Stores plane equation coefficients (in the following form: //! Ax + By + Cz + D = 0) to the given vector virtual void GetPlanes (NCollection_Vector& thePlaneEquations) const Standard_OVERRIDE diff --git a/src/SelectMgr/SelectMgr_ViewClipRange.hxx b/src/SelectMgr/SelectMgr_ViewClipRange.hxx index 97deae09c9..ad5f893131 100644 --- a/src/SelectMgr/SelectMgr_ViewClipRange.hxx +++ b/src/SelectMgr/SelectMgr_ViewClipRange.hxx @@ -18,6 +18,7 @@ #include #include +#include //! Class for handling depth clipping range. //! It is used to perform checks in case if global (for the whole view) @@ -62,6 +63,16 @@ public: //! Adds a clipping sub-range (for clipping chains). void AddClipSubRange (const Bnd_Range& theRange) { myClipRanges.push_back (theRange); } + //! Dumps the content of me on the stream . + Standard_EXPORT void Dump (Standard_OStream& OS) const + { + DUMP_VALUES (OS, "SelectMgr_ViewClipRange", 2); + DUMP_VALUES (OS, "myUnclipRange", myUnclipRange.ToString()); + DUMP_VALUES (OS, "myClipRanges", myClipRanges.size()); + for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter) + DUMP_VALUES (OS, aRangeIter, myClipRanges[aRangeIter].ToString()); + } + private: std::vector myClipRanges; diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.cxx b/src/SelectMgr/SelectMgr_ViewerSelector.cxx index a0f8cddbb2..745f405006 100644 --- a/src/SelectMgr/SelectMgr_ViewerSelector.cxx +++ b/src/SelectMgr/SelectMgr_ViewerSelector.cxx @@ -36,7 +36,7 @@ #include -//#define REPORT_SELECTION_BUILD +#define REPORT_SELECTION_BUILD #ifdef REPORT_SELECTION_BUILD #include #include @@ -280,6 +280,16 @@ void SelectMgr_ViewerSelector::checkOverlap (const Handle(SelectBasics_Sensitive return; } + if (!mySelectingVolumeMgr.ViewClipping().IsNull()) + { + Standard_Real aDepth = /*aPickResult.HasPickedPoint() ?*+/ aPickResult.Depth();// :*/ aPickResult.DistToGeomCenter(); + Standard_Boolean isClipped = mySelectingVolumeMgr.IsClipped (*mySelectingVolumeMgr.ViewClipping(), + aDepth); + if (isClipped) + return; + else + int aValue = 9; + } if (HasDepthClipping (anOwner) && !aSelectable.IsNull() && theMgr.GetActiveSelectionType() == SelectMgr_SelectingVolumeManager::Point) @@ -618,6 +628,7 @@ void SelectMgr_ViewerSelector::TraverseSensitives() Standard_Integer aWidth; Standard_Integer aHeight; mySelectingVolumeMgr.WindowSize (aWidth, aHeight); + MESSAGE_INFO ("UpdateBVH", "", &aPerfMeter, aParentAlert); mySelectableObjects.UpdateBVH (mySelectingVolumeMgr.Camera(), mySelectingVolumeMgr.ProjectionMatrix(), mySelectingVolumeMgr.WorldViewMatrix(), @@ -637,14 +648,14 @@ void SelectMgr_ViewerSelector::TraverseSensitives() for (Standard_Integer aBVHSetIt = 0; aBVHSetIt < SelectMgr_SelectableObjectSet::BVHSubsetNb; ++aBVHSetIt) { + SelectMgr_SelectableObjectSet::BVHSubset aBVHSubset = + static_cast (aBVHSetIt); + #ifdef REPORT_SELECTION_BUILD - MESSAGE_INFO (TCollection_AsciiString ("aBVHSetIt") + aBVHSetIt, "", &aPerfMeter, aParentAlert); + MESSAGE_INFO (TCollection_AsciiString ("aBVHSetIt"), SelectMgr::BVHSubsetToString (aBVHSubset), &aPerfMeter, aParentAlert); Handle(Message_Alert) aParentAlertLevel1 = OCCT_Message_Alert; #endif - SelectMgr_SelectableObjectSet::BVHSubset aBVHSubset = - static_cast (aBVHSetIt); - if (mySelectableObjects.IsEmpty (aBVHSubset)) { continue; @@ -756,6 +767,7 @@ void SelectMgr_ViewerSelector::TraverseSensitives() } } + MESSAGE_INFO ("SortResult", "", &aPerfMeter, aParentAlert); SortResult(); #ifdef REPORT_SELECTION_BUILD Standard_SStream aStreamDone; diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.hxx b/src/SelectMgr/SelectMgr_ViewerSelector.hxx index 753d3f9e5a..7fc5d34690 100644 --- a/src/SelectMgr/SelectMgr_ViewerSelector.hxx +++ b/src/SelectMgr/SelectMgr_ViewerSelector.hxx @@ -205,6 +205,12 @@ public: //! Returns instance of selecting volume manager of the viewer selector SelectMgr_SelectingVolumeManager& GetManager() { return mySelectingVolumeMgr; } + //! Returns container of selectable objects + const SelectMgr_SelectableObjectSet& GetSelectableObjects() const { return mySelectableObjects; } + + //! Returns container of sensitives + const SelectMgr_MapOfObjectSensitives& GetObjectSensitives() const { return myMapOfObjectSensitives; } + //! Marks all added sensitive entities of all objects as non-selectable Standard_EXPORT void ResetSelectionActivationStatus(); diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index 8ed26b7c6d..ffa6f21abb 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -69,7 +69,7 @@ #include -//#define REPORT_SELECTION_BUILD +#define REPORT_SELECTION_BUILD #ifdef REPORT_SELECTION_BUILD #include #include @@ -162,6 +162,15 @@ void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin, const Standard_Integer theYPMax, const Handle(V3d_View)& theView) { +#ifdef REPORT_SELECTION_BUILD + Message_PerfMeter aPerfMeter; + MESSAGE_INFO ("Pick", TCollection_AsciiString ("min/max: (") + + theXPMin + ", " + theYPMin + ") / (" + + theXPMax + ", " + theYPMax + ") " + , &aPerfMeter, NULL); + Handle(Message_Alert) aParentAlert = OCCT_Message_Alert; +#endif + updateZLayers (theView); mySelectingVolumeMgr.SetCamera (theView->Camera()); mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box); diff --git a/src/TopoDS/TopoDS_AlertAttribute.hxx b/src/TopoDS/TopoDS_AlertAttribute.hxx index 115a9ec28e..f0708407cd 100644 --- a/src/TopoDS/TopoDS_AlertAttribute.hxx +++ b/src/TopoDS/TopoDS_AlertAttribute.hxx @@ -24,9 +24,10 @@ class TopoDS_AlertAttribute : public Message_Attribute { public: //! Constructor with shape argument - Standard_EXPORT TopoDS_AlertAttribute (const TopoDS_Shape& theShape, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); + TopoDS_AlertAttribute (const TopoDS_Shape& theShape, + const TCollection_AsciiString& theName = TCollection_AsciiString(), + const TCollection_AsciiString& theDescription = TCollection_AsciiString()) + : Message_Attribute (theName, theDescription), myShape (theShape) {} //! Returns contained shape const TopoDS_Shape& GetShape() const { return myShape; } diff --git a/src/gp/gp_XY.hxx b/src/gp/gp_XY.hxx index 70ffa21f58..cb451b135e 100644 --- a/src/gp/gp_XY.hxx +++ b/src/gp/gp_XY.hxx @@ -22,6 +22,9 @@ #include #include #include + +#include + class Standard_ConstructionError; class Standard_OutOfRange; class gp_Mat2d; @@ -269,6 +272,15 @@ public: } + //! Covers point into string in format: (X, Y) + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const; + + + //! Converts text value into parameters if possible, the string format is: (X, Y) + //! \return true if conversion is done + Standard_EXPORT Standard_Boolean FromString (const TCollection_AsciiString& theValue); + protected: diff --git a/src/gp/gp_XY.lxx b/src/gp/gp_XY.lxx index ecd0605719..12fc78c19e 100644 --- a/src/gp/gp_XY.lxx +++ b/src/gp/gp_XY.lxx @@ -227,3 +227,37 @@ inline gp_XY operator* (const Standard_Real Scalar, return Coord1.Multiplied(Scalar); } +inline TCollection_AsciiString gp_XY::ToString() const +{ + return TCollection_AsciiString ("(") + x + ", " + y + ")"; +} + +inline Standard_Boolean gp_XY::FromString (const TCollection_AsciiString& theValue) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + Standard_Integer aPosition = aCurrentString.Search ("("); + if (aPosition != 1) + return Standard_False; + + aCurrentString = aCurrentString.Split (aPosition); + Standard_Real aX, anY; + // x value + aPosition = aCurrentString.Search (", "); + if (aPosition < 0) + return Standard_False; + aCurrentString = aValueString.Split (aPosition); + aX = aValueString.RealValue(); + aCurrentString = aCurrentString.Split (2); + + // y value + aPosition = aCurrentString.Search (")"); + if (aPosition < 0) + return Standard_False; + aCurrentString = aValueString.Split (aPosition); + anY = aValueString.RealValue(); + + x = aX; + y = anY; + return Standard_True; +} diff --git a/src/gp/gp_XYZ.hxx b/src/gp/gp_XYZ.hxx index ccb0373c09..34572eaa40 100644 --- a/src/gp/gp_XYZ.hxx +++ b/src/gp/gp_XYZ.hxx @@ -22,6 +22,9 @@ #include #include #include + +#include + class Standard_ConstructionError; class Standard_OutOfRange; class gp_Mat; @@ -324,6 +327,14 @@ public: void SetLinearForm (const gp_XYZ& XYZ1, const gp_XYZ& XYZ2); + //! Covers point into string in format: (X, Y, Z) + //! \return the string value + Standard_EXPORT TCollection_AsciiString ToString() const; + + + //! Converts text value into parameters if possible, the string format is: (X, Y, Z) + //! \return true if conversion is done + Standard_EXPORT Standard_Boolean FromString (const TCollection_AsciiString& theValue); protected: diff --git a/src/gp/gp_XYZ.lxx b/src/gp/gp_XYZ.lxx index f97590738c..c4dde68a65 100644 --- a/src/gp/gp_XYZ.lxx +++ b/src/gp/gp_XYZ.lxx @@ -307,7 +307,50 @@ inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) { } +inline TCollection_AsciiString gp_XYZ::ToString() const +{ + return TCollection_AsciiString ("(") + x + ", " + y + ", " + z + ")"; +} - - +inline Standard_Boolean gp_XYZ::FromString (const TCollection_AsciiString& theValue) +{ + TCollection_AsciiString aCurrentString = theValue, aValueString; + + Standard_Integer aPosition = aCurrentString.Search ("("); + if (aPosition != 1) + return Standard_False; + + aCurrentString = aCurrentString.Split (aPosition); + Standard_Real aX, anY, aZ; + // x value + aPosition = aCurrentString.Search (", "); + if (aPosition < 0) + return Standard_False; + aValueString = aCurrentString; + aCurrentString = aValueString.Split (aPosition - 1); + aX = aValueString.RealValue(); + aCurrentString = aCurrentString.Split (2); + + // y value + aPosition = aCurrentString.Search (", "); + if (aPosition < 0) + return Standard_False; + aValueString = aCurrentString; + aCurrentString = aValueString.Split (aPosition - 1); + anY = aValueString.RealValue(); + aCurrentString = aCurrentString.Split (2); + + // z value + aPosition = aCurrentString.Search (")"); + if (aPosition < 0) + return Standard_False; + aValueString = aCurrentString; + aCurrentString = aValueString.Split (aPosition); + aZ = aValueString.RealValue(); + + x = aX; + y = anY; + z = aZ; + return Standard_True; +} diff --git a/tests/v3d/glsl/clipping_selection_box b/tests/v3d/glsl/clipping_selection_box new file mode 100644 index 0000000000..c70d4be1d0 --- /dev/null +++ b/tests/v3d/glsl/clipping_selection_box @@ -0,0 +1,41 @@ +# creating three 3D objects +# cut view scene by clipping plane +# expecting two objects selected + +pload ALL +vinit View1 + +box b 10 10 10 +vdisplay b + +box b1 -5 0 0 2 2 2 +vdisplay b1 + +box b2 13 0 0 2 2 2 +vdisplay b2 + +vsetdispmode 1 + +vclipplane create pln +vclipplane set pln view Driver1/Viewer1/View1 +vclipplane change pln equation -1 0 0 5 + +vtop +vfit +vzoom 0.5 +vselect 40 100 370 300 + +# expected result is 2 objects, but clipping is not applyed for selection by box +vnbselected + +# check selected elements in Inspector +pload INSPECTOR +tinspector –plugins vinspector +tinspector –plugins messageview +tinspector –activate messageview +activateReport +tinspector -update + +# see messages from selection preparing in Inspector +vselect 40 100 370 300 + diff --git a/tools/MessageModel/MessageModel_Actions.cxx b/tools/MessageModel/MessageModel_Actions.cxx index 4a587b5591..140aaaf043 100644 --- a/tools/MessageModel/MessageModel_Actions.cxx +++ b/tools/MessageModel/MessageModel_Actions.cxx @@ -121,7 +121,9 @@ void MessageModel_Actions::AddMenuActions (const QModelIndexList& theSelectedInd #endif } else if (anAlertItem) + { theMenu->addAction (myActions[MessageModel_ActionType_ExportToShapeView]); + } theMenu->addSeparator(); } diff --git a/tools/MessageModel/MessageModel_ItemAlert.cxx b/tools/MessageModel/MessageModel_ItemAlert.cxx index c05a71b800..b94e5ac006 100644 --- a/tools/MessageModel/MessageModel_ItemAlert.cxx +++ b/tools/MessageModel/MessageModel_ItemAlert.cxx @@ -18,12 +18,16 @@ #include #include #include +#include +#include #include #include +#include #include #include +#include #include #include @@ -32,6 +36,7 @@ #include #include + // ======================================================================= // function : initValue // purpose : @@ -208,6 +213,23 @@ void MessageModel_ItemAlert::Init() } } } + + Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(myAlert); + if (!anExtendedAlert.IsNull() && !anExtendedAlert->Attribute().IsNull()) + { + Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute(); + if (!anAttribute.IsNull()) + { + if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject))) + myPresentations.Append (Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject()); + if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) + myPresentations.Append (new ViewControl_TransientShape (Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape())); + } + TCollection_AsciiString aDescription = anExtendedAlert->Attribute()->GetDescription(); + Bnd_Box aBox; + if (aBox.FromString (aDescription)) + myPresentations.Append (new ViewControl_TransientShape (ViewControl_Tools::CreateShape (aBox))); + } MessageModel_ItemBase::Init(); } @@ -221,6 +243,7 @@ void MessageModel_ItemAlert::Reset() myAlert = Handle(Message_Alert)(); myUnitedAlerts.Clear(); myChildAlerts.Clear(); + myPresentations.Clear(); } // ======================================================================= diff --git a/tools/MessageModel/MessageModel_ItemAlert.hxx b/tools/MessageModel/MessageModel_ItemAlert.hxx index f32df889d7..f139fb54c2 100644 --- a/tools/MessageModel/MessageModel_ItemAlert.hxx +++ b/tools/MessageModel/MessageModel_ItemAlert.hxx @@ -29,6 +29,7 @@ #include #include +#include #include class QAbstractTableModel; @@ -84,6 +85,14 @@ public: //! \return instance of the shape const TopoDS_Shape& GetCustomShape() const { return myCustomShape; } + //! Returns presentation of the attribute to be visualized in the view + //! \param theRow a model index row + //! \param theColumn a model index column + //! \thePresentations [out] container of presentation handles to be visualized + void GetPresentations (NCollection_List& thePresentations) + { thePresentations.Append (myPresentations); } + + //! Returns summ of children alert elapsed times. The method is recusive. //! \param theAlert a message alert //! \return double value @@ -126,6 +135,7 @@ private: NCollection_DataMap myChildAlerts; //!< container of child alerts TopoDS_Shape myCustomShape; + NCollection_List myPresentations; }; #endif diff --git a/tools/MessageModel/MessageModel_ItemReport.cxx b/tools/MessageModel/MessageModel_ItemReport.cxx index bc4c4877e4..a2af8df74e 100644 --- a/tools/MessageModel/MessageModel_ItemReport.cxx +++ b/tools/MessageModel/MessageModel_ItemReport.cxx @@ -204,3 +204,24 @@ double MessageModel_ItemReport::AmountElapsedTime (const Handle(Message_Report)& } return anAmountTime; } + +// ======================================================================= +// function : FindReport +// purpose : +// ======================================================================= +Handle(Message_Report) MessageModel_ItemReport::FindReport (const MessageModel_ItemBasePtr& theItem) +{ + Handle(Message_Report) aReport; + + MessageModel_ItemBasePtr anItem = theItem; + while (anItem) + { + MessageModel_ItemReportPtr aReportItem = itemDynamicCast(anItem); + + if (aReportItem) + return aReportItem->GetReport(); + + anItem = itemDynamicCast(anItem->Parent()); + } + return NULL; +} diff --git a/tools/MessageModel/MessageModel_ItemReport.hxx b/tools/MessageModel/MessageModel_ItemReport.hxx index c6ce246fc2..d76b56b466 100644 --- a/tools/MessageModel/MessageModel_ItemReport.hxx +++ b/tools/MessageModel/MessageModel_ItemReport.hxx @@ -80,6 +80,9 @@ public: //! \return double value Standard_EXPORT static double AmountElapsedTime (const Handle(Message_Report)& theReport); + //! Returns report of the item + static Handle(Message_Report) FindReport (const MessageModel_ItemBasePtr& thetItem); + protected: //! Initialize the current item. It is empty because Reset() is also empty. diff --git a/tools/MessageView/MessageView_VisibilityState.cxx b/tools/MessageView/MessageView_VisibilityState.cxx index 8b4207b8fb..cec2d932df 100644 --- a/tools/MessageView/MessageView_VisibilityState.cxx +++ b/tools/MessageView/MessageView_VisibilityState.cxx @@ -27,6 +27,15 @@ // ======================================================================= bool MessageView_VisibilityState::CanBeVisible (const QModelIndex& theIndex) const { + MessageModel_ItemAlertPtr anAlertItem = getAlertItem (theIndex); + if (anAlertItem) + { + NCollection_List aPresentations; + anAlertItem->GetPresentations (aPresentations); + if (!aPresentations.IsEmpty()) + return true; + } + return !getShape (theIndex).IsNull();// || hasTableValues (theIndex); } diff --git a/tools/MessageView/MessageView_Window.cxx b/tools/MessageView/MessageView_Window.cxx index c0c0aebf39..ad8895e831 100644 --- a/tools/MessageView/MessageView_Window.cxx +++ b/tools/MessageView/MessageView_Window.cxx @@ -30,11 +30,14 @@ #include #include #include +#include #include +#include +#include #include - +#include #include #include @@ -98,6 +101,39 @@ const int MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT = 500; const int MESSAGEVIEW_DEFAULT_VIEW_WIDTH = 200;// 400; const int MESSAGEVIEW_DEFAULT_VIEW_HEIGHT = 300;// 1000; +#include +#include +Handle(Prs3d_Drawer) GetPreviewAttributes (const Handle(AIS_InteractiveContext)& theContext) +{ + Handle(Prs3d_Drawer) myDrawer = new Prs3d_Drawer(); + myDrawer->Link (theContext->DefaultDrawer()); + + Quantity_Color aColor(Quantity_NOC_TOMATO);//Quantity_NOC_GREENYELLOW));//Quantity_NOC_BLUE1)); + Standard_ShortReal aTransparency = 0.8; + + // point parameters + myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0)); + + // shading parameters + Graphic3d_MaterialAspect aShadingMaterial; + aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + + myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); + 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); + + return myDrawer; +} + // ======================================================================= // function : Constructor // purpose : @@ -294,6 +330,7 @@ void MessageView_Window::Init (NCollection_List& the NCollection_List aParameters; Handle(Message_ReportCallBack) aReportCallBack; + Handle(Graphic3d_Camera) aViewCamera; for (NCollection_List::Iterator aParamsIt (theParameters); aParamsIt.More(); aParamsIt.Next()) @@ -305,23 +342,31 @@ void MessageView_Window::Init (NCollection_List& the aMessageReport->SetCallBack (myCallBack); addReport (aMessageReport); } - else + else if (!Handle(AIS_InteractiveContext)::DownCast (anObject).IsNull()) { aParameters.Append (anObject); if (aContext.IsNull()) aContext = Handle(AIS_InteractiveContext)::DownCast (anObject); } + else if (!Handle(Graphic3d_Camera)::DownCast (anObject).IsNull()) + { + aViewCamera = Handle(Graphic3d_Camera)::DownCast (anObject); + } } - QAbstractItemModel* aModel = myTreeView->model(); - if (!aModel) - return; - MessageModel_TreeModel* aTreeModel = dynamic_cast (aModel); + MessageModel_TreeModel* aTreeModel = dynamic_cast (myTreeView->model()); if (!aTreeModel) return; + aTreeModel->EmitLayoutChanged(); if (!aContext.IsNull()) + { + myContext = aContext; myViewWindow->SetContext (View_ContextType_External, aContext); + } + + if (!aViewCamera.IsNull()) + myViewWindow->GetView()->GetViewer()->GetView()->Camera()->Copy (aViewCamera); theParameters = aParameters; } @@ -385,6 +430,26 @@ void MessageView_Window::onTreeViewSelectionChanged (const QItemSelection&, cons return; updatePropertyPanelBySelection(); + + NCollection_List aPresentations; + MessageModel_ItemRootPtr aRootItem; + QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes(); + for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++) + { + QModelIndex anIndex = *aSelIt; + if (anIndex.column() != 0) + continue; + + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + continue; + + MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast(anItemBase); + if (!anAlertItem) + continue; + anAlertItem->GetPresentations (aPresentations); + } + updatePreviewPresentation (aPresentations); } // ======================================================================= @@ -647,3 +712,76 @@ void MessageView_Window::updatePropertyPanelBySelection() myPropertyView->Init (aTableValues); } + +// ======================================================================= +// function : updatePreviewPresentation +// purpose : +// ======================================================================= +void MessageView_Window::updatePreviewPresentation (const NCollection_List& thePresentations) +{ + if (myContext.IsNull()) + return; + + Handle(AIS_InteractiveContext) aContext = myContext; + + if (!myPreviewPresentations.IsEmpty()) + { + for (NCollection_List::Iterator aDisplayedIt (myPreviewPresentations); aDisplayedIt.More(); aDisplayedIt.Next()) + { + Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast (aDisplayedIt.Value()); + if (!aPrs.IsNull()) + aContext->Remove (aPrs, Standard_True); + } + } + myPreviewPresentations.Clear(); + + myPreviewPresentations = thePresentations; + if (myPreviewPresentations.IsEmpty()) + return; + + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + for (NCollection_List::Iterator aDisplayedIt (myPreviewPresentations); aDisplayedIt.More(); aDisplayedIt.Next()) + { + Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast (aDisplayedIt.Value()); + if (!aPrs.IsNull()) + { + aContext->Display (aPrs, AIS_Shaded, -1/*do not participate in selection*/, Standard_True); + } + else if (!Handle(ViewControl_TransientShape)::DownCast (aDisplayedIt.Value()).IsNull()) + { + Handle(ViewControl_TransientShape) aShapeObject = Handle(ViewControl_TransientShape)::DownCast (aDisplayedIt.Value()); + aBuilder.Add (aCompound, aShapeObject->GetShape()); + } + } + + if (aCompound.IsNull()) + { + if (!aContext.IsNull()) + aContext->Remove (myPreviewPresentation, Standard_True); + myPreviewPresentation = NULL; + return; + + } + else + { + if (myPreviewPresentation.IsNull()) + { + myPreviewPresentation = new AIS_Shape (aCompound); + myPreviewPresentation->SetAttributes (GetPreviewAttributes(myContext)); + //myPreviewPresentation->SetAttributes (myPreviewParameters->GetDrawer()); + + //myPreviewPresentation->SetTransformPersistence(thePersistent); + if (!aContext.IsNull()) + aContext->Display (myPreviewPresentation, AIS_Shaded, -1/*do not participate in selection*/, Standard_True); + } + else + { + Handle(AIS_Shape)::DownCast (myPreviewPresentation)->Set (aCompound); + //myPreviewPresentation->SetTransformPersistence(thePersistent); + if (!aContext.IsNull()) + aContext->Redisplay (myPreviewPresentation, Standard_True); + } + } +} diff --git a/tools/MessageView/MessageView_Window.hxx b/tools/MessageView/MessageView_Window.hxx index 31d5b4ce7b..a4ace53694 100644 --- a/tools/MessageView/MessageView_Window.hxx +++ b/tools/MessageView/MessageView_Window.hxx @@ -21,9 +21,12 @@ #include #include - #include +#include +#include +#include + #ifdef _MSC_VER #pragma warning(disable : 4127) // conditional expression is constant #endif @@ -158,6 +161,10 @@ protected: //! Updates property panel content by item selected in tree view. void updatePropertyPanelBySelection(); + //!< Updates presentation of preview for parameter shapes. Creates a compound of the shapes + //!< \param theShape container of shapes + void updatePreviewPresentation (const NCollection_List& thePresentations); + private: QMainWindow* myMainWindow; //!< main control, parent for all MessageView controls QDockWidget* myViewDockWidget; //!< view dock widget to hide/show @@ -171,6 +178,10 @@ private: Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container Handle(Message_ReportCallBack) myCallBack; //! < message call back to update content of the view + + Handle(AIS_InteractiveContext) myContext; //! current context + Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object + NCollection_List myPreviewPresentations; }; #endif diff --git a/tools/TInspectorEXE/TInspectorEXE.cxx b/tools/TInspectorEXE/TInspectorEXE.cxx index 3d3fd45304..5743c1e0d1 100644 --- a/tools/TInspectorEXE/TInspectorEXE.cxx +++ b/tools/TInspectorEXE/TInspectorEXE.cxx @@ -66,7 +66,7 @@ void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspecto aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep"); else if (theName.IsEqual ("TKVInspector")) { - aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep"); + //aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep"); anAdditionalFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep"); } aRecentlyOpenedFiles.append (aFileName.ToCString()); @@ -127,8 +127,8 @@ int main (int argc, char** argv) aPlugins.insert("TKVInspector"); Handle(Message_Report) aReport = Message_Report::CurrentReport (Standard_True); - aReport->SetLimit(30); - aReport->SetActive (Standard_False); + aReport->SetLimit (100);//30); + aReport->SetActive (Standard_True);//Standard_False); aPlugins.insert("TKMessageView"); anActivatedPluginName = "TKVInspector"; diff --git a/tools/TKTreeModel/EXTERNLIB b/tools/TKTreeModel/EXTERNLIB index 100866c7f3..faee5c912f 100644 --- a/tools/TKTreeModel/EXTERNLIB +++ b/tools/TKTreeModel/EXTERNLIB @@ -1,3 +1,5 @@ TKernel TKMath +TKPrim +TKTopAlgo CSF_QT \ No newline at end of file diff --git a/tools/TreeModel/TreeModel_ItemBase.cxx b/tools/TreeModel/TreeModel_ItemBase.cxx index 703414f403..3efee94260 100644 --- a/tools/TreeModel/TreeModel_ItemBase.cxx +++ b/tools/TreeModel/TreeModel_ItemBase.cxx @@ -65,6 +65,9 @@ void TreeModel_ItemBase::Reset() } m_bInitialized = false; myCachedValues.clear(); + + if (!GetProperties().IsNull()) + GetProperties()->Reset(); } // ======================================================================= diff --git a/tools/TreeModel/TreeModel_ItemBase.hxx b/tools/TreeModel/TreeModel_ItemBase.hxx index b7f3f7b634..45da4d7805 100644 --- a/tools/TreeModel/TreeModel_ItemBase.hxx +++ b/tools/TreeModel/TreeModel_ItemBase.hxx @@ -19,6 +19,8 @@ #include #include #include +#include + #include #include @@ -139,9 +141,13 @@ public: //! Returns item table properties builder Standard_EXPORT Handle(TreeModel_ItemProperties) GetProperties() const; + //! Dumps the content of me on the stream . + virtual Standard_Boolean Dump (Standard_OStream& OS) const { (void)OS; return Standard_False; } + //! Returns number of item rows only static Standard_EXPORT int RowCountWithoutProperties (const TreeModel_ItemBasePtr& theItem); + protected: //! \param theParent the parent item diff --git a/tools/TreeModel/TreeModel_ItemProperties.hxx b/tools/TreeModel/TreeModel_ItemProperties.hxx index d096f71394..a7a41282c6 100644 --- a/tools/TreeModel/TreeModel_ItemProperties.hxx +++ b/tools/TreeModel/TreeModel_ItemProperties.hxx @@ -48,6 +48,12 @@ public: //! Destructor ~TreeModel_ItemProperties() {} + //! If me has internal values, it should be initialized here. + virtual void Init() {} + + //! If the item has internal values, there should be reseted here. + Standard_EXPORT virtual void Reset() {} + //! Returns number of item children //! \return an integer value, ZERO by default virtual int ChildItemCount() const { return 0; } @@ -59,7 +65,7 @@ public: virtual TreeModel_ItemBasePtr CreateChildItem (int theRow, int theColumn) const { (void)theRow; (void)theColumn; return TreeModel_ItemBasePtr(); } - //! Returns number of table rows + //! Returns number of table columns. Default value is two columns: title to value //! \return an integer value virtual int GetTableColumnCount() const { return 2; } diff --git a/tools/VInspector/FILES b/tools/VInspector/FILES index 744181b067..983606430e 100644 --- a/tools/VInspector/FILES +++ b/tools/VInspector/FILES @@ -9,6 +9,13 @@ VInspector_ItemAspectWindow.cxx VInspector_ItemAspectWindow.hxx VInspector_ItemBase.cxx VInspector_ItemBase.hxx +VInspector_ItemBVHTree.cxx +VInspector_ItemBVHTree.hxx +VInspector_ItemBVHTreeNode.cxx +VInspector_ItemBVHTreeNode.hxx +VInspector_ItemContainer.cxx +VInspector_ItemContainer.hxx +VInspector_ItemContainerAPI.hxx VInspector_ItemContext.cxx VInspector_ItemContext.hxx VInspector_ItemFolderObject.cxx @@ -32,12 +39,16 @@ VInspector_ItemHistoryRoot.hxx VInspector_ItemHistoryType.cxx VInspector_ItemHistoryType.hxx VInspector_ItemHistoryTypeInfo.hxx +VInspector_ItemOpenGlContext.cxx +VInspector_ItemOpenGlContext.hxx VInspector_ItemOpenGlElement.cxx VInspector_ItemOpenGlElement.hxx VInspector_ItemOpenGlLayer.cxx VInspector_ItemOpenGlLayer.hxx VInspector_ItemOpenGlLayerList.cxx VInspector_ItemOpenGlLayerList.hxx +VInspector_ItemOpenGlWindow.cxx +VInspector_ItemOpenGlWindow.hxx VInspector_ItemPresentableObject.cxx VInspector_ItemPresentableObject.hxx VInspector_ItemPresentations.cxx @@ -62,16 +73,24 @@ VInspector_ItemSelectMgrBaseFrustum.cxx VInspector_ItemSelectMgrBaseFrustum.hxx VInspector_ItemSelectMgrFilter.cxx VInspector_ItemSelectMgrFilter.hxx +VInspector_ItemSelectMgrSelectableObjectSet.cxx +VInspector_ItemSelectMgrSelectableObjectSet.hxx VInspector_ItemSelectMgrSelectingVolumeManager.cxx VInspector_ItemSelectMgrSelectingVolumeManager.hxx VInspector_ItemSelectMgrSelection.cxx VInspector_ItemSelectMgrSelection.hxx VInspector_ItemSelectMgrSensitiveEntity.cxx VInspector_ItemSelectMgrSensitiveEntity.hxx +VInspector_ItemSelectMgrSensitiveEntitySet.cxx +VInspector_ItemSelectMgrSensitiveEntitySet.hxx VInspector_ItemV3dView.cxx VInspector_ItemV3dView.hxx VInspector_ItemV3dViewer.cxx VInspector_ItemV3dViewer.hxx +VInspector_PreviewParameters.cxx +VInspector_PreviewParameters.hxx +VInspector_PropertiesCreator.cxx +VInspector_PropertiesCreator.hxx VInspector_PrsOpenGlElement.cxx VInspector_PrsOpenGlElement.hxx VInspector_SelectionType.hxx diff --git a/tools/VInspector/VInspector_ItemBVHTree.cxx b/tools/VInspector/VInspector_ItemBVHTree.cxx new file mode 100644 index 0000000000..8bcd7e328e --- /dev/null +++ b/tools/VInspector/VInspector_ItemBVHTree.cxx @@ -0,0 +1,196 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +VInspector_ItemBVHTree::VInspector_ItemBVHTree (TreeModel_ItemBasePtr theParent, + const int theRow, const int theColumn) +: VInspector_ItemBase(theParent, theRow, theColumn) +{ +} + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemBVHTree::initRowCount() const +{ + if (Column() != 0) + return 0; + + opencascade::handle > aTree = GetTree(); + if (aTree.IsNull()) + return 0; + + return aTree->Length(); +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemBVHTree::initValue (const int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + if (GetTree().IsNull()) + return Column() == 0 ? "Empty BVH tree" : ""; + + switch (Column()) + { + case 0: + { + TCollection_AsciiString aName = TCollection_AsciiString (GetTree()->DynamicType()->Name()) + + TCollection_AsciiString (" (") + myName.ToCString() + ")"; + return aName.ToCString(); + } + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTree::Init() +{ + VInspector_ItemSelectMgrSelectableObjectSetPtr anObjectParent = itemDynamicCast(Parent()); + opencascade::handle > aBVHTree; + if (anObjectParent) + { + aBVHTree = anObjectParent->GetBVHTree (Row(), myName); + } + else + { + VInspector_ItemSelectMgrSensitiveEntitySetPtr anEntityParent = itemDynamicCast(Parent()); + if (anEntityParent) + aBVHTree = anEntityParent->GetBVHTree (Row(), myName); + } + + setTree (aBVHTree); + + UpdatePresentationShape(); + TreeModel_ItemBase::Init(); // to use getIO() without circling initialization +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTree::Reset() +{ + VInspector_ItemBase::Reset(); + + setTree (NULL); + myName = TCollection_AsciiString(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTree::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : Dump +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemBVHTree::Dump (Standard_OStream& OS) const +{ + opencascade::handle > aBVHTree = GetTree(); + if (aBVHTree.IsNull()) + return Standard_False; + + aBVHTree->Dump (OS); + return Standard_True; +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemBVHTree::createChild (int theRow, int theColumn) +{ + return VInspector_ItemBVHTreeNode::CreateItem (currentItem(), theRow, theColumn); +} + +// ======================================================================= +// function : buildPresentationShape +// purpose : +// ======================================================================= +TopoDS_Shape VInspector_ItemBVHTree::buildPresentationShape() +{ + opencascade::handle > aBVHTree = myTree; + if (aBVHTree.IsNull()) + return TopoDS_Shape(); + + Standard_SStream OS; + //aBVHTree->DumpNode (Row(), OS); + aBVHTree->Dump (OS); + + Standard_Integer aColumnCount; + NCollection_Vector aValues; + Message::ConvertStream (OS, aColumnCount, aValues); + + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + for (int aValueId = 0; aValueId < aValues.Size(); ) + { + for (int aColumnId = 0; aColumnId < aColumnCount; aColumnId++, aValueId++) + { + if (aColumnId != 1) + continue; + + TCollection_AsciiString aValue = aValues.Value (aValueId); + Bnd_Box aBox; + if (!aBox.FromString (aValue)) + continue; + + TopoDS_Shape aShape = VInspector_Tools::CreateShape (aBox); + aBuilder.Add (aCompound, aShape); + } + } + return aCompound; +} diff --git a/tools/VInspector/VInspector_ItemBVHTree.hxx b/tools/VInspector/VInspector_ItemBVHTree.hxx new file mode 100644 index 0000000000..a72ca7e2e7 --- /dev/null +++ b/tools/VInspector/VInspector_ItemBVHTree.hxx @@ -0,0 +1,105 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemBVHTree_H +#define VInspector_ItemBVHTree_H + +#include +#include + +#include +#include +#include + +class VInspector_ItemBVHTree; +typedef QExplicitlySharedDataPointer VInspector_ItemBVHTreePtr; + +//! \class VInspector_ItemBVHTree +//! Parent item, that corresponds Folder under the AIS_InteractiveContext +//! Children of the item are: none +class VInspector_ItemBVHTree : public VInspector_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemBVHTreePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemBVHTreePtr (new VInspector_ItemBVHTree (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemBVHTree() Standard_OVERRIDE {}; + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return myTree; } + + //! Returns current drawer, initialize the drawer if it was not initialized yet + opencascade::handle > GetTree() const + { return opencascade::handle >::DownCast (GetObject()); } + + //! Dumps the content of me on the stream . + virtual Standard_Boolean Dump (Standard_OStream& OS) const; + +protected: + //! Initialize the current item. It is empty because Reset() is also empty. + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + + //! Build presentation shape + //! \return generated shape of the item parameters + virtual TopoDS_Shape buildPresentationShape() Standard_OVERRIDE; + +protected: + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Set V3d viewer selector into the current field + //! \param theTree a viewer selector + void setTree (const opencascade::handle >& theTree) { myTree = theTree; } + +private: + + //! Constructor + //! param theParent a parent item + //! \param theRow the item row positition in the parent item + //! \param theColumn the item column positition in the parent item + VInspector_ItemBVHTree(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn); + +private: + + opencascade::handle > myTree; //!< the current tree + TCollection_AsciiString myName; //!< the name +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemBVHTreeNode.cxx b/tools/VInspector/VInspector_ItemBVHTreeNode.cxx new file mode 100644 index 0000000000..061539e303 --- /dev/null +++ b/tools/VInspector/VInspector_ItemBVHTreeNode.cxx @@ -0,0 +1,162 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +//#include +// +#include + +#include +#include + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemBVHTreeNode::initRowCount() const +{ + return 0; +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemBVHTreeNode::initValue (const int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + switch (Column()) + { + case 0: return QString ("TreeNode_%1").arg (Row()); break; + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTreeNode::Init() +{ + UpdatePresentationShape(); + TreeModel_ItemBase::Init(); // to use getIO() without circling initialization +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTreeNode::Reset() +{ + VInspector_ItemBase::Reset(); +} + +// ======================================================================= +// function : GetTree +// purpose : +// ======================================================================= + +opencascade::handle > VInspector_ItemBVHTreeNode::GetTree() const +{ + VInspector_ItemBVHTreePtr anObjectParent = itemDynamicCast(Parent()); + + return anObjectParent->GetTree(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= + +void VInspector_ItemBVHTreeNode::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemBVHTreeNode::createChild (int, int) +{ + return TreeModel_ItemBasePtr(); +} + +// ======================================================================= +// function : buildPresentationShape +// purpose : +// ======================================================================= +TopoDS_Shape VInspector_ItemBVHTreeNode::buildPresentationShape() +{ + opencascade::handle > aBVHTree = GetTree(); + if (aBVHTree.IsNull()) + return TopoDS_Shape(); + + Standard_SStream OS; + aBVHTree->DumpNode (Row(), OS); + + Standard_Integer aColumnCount; + NCollection_Vector aValues; + Message::ConvertStream (OS, aColumnCount, aValues); + + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + for (int aValueId = 0; aValueId < aValues.Size(); ) + { + for (int aColumnId = 0; aColumnId < aColumnCount; aColumnId++, aValueId++) + { + if (aColumnId != 1) + continue; + + TCollection_AsciiString aValue = aValues.Value (aValueId); + Bnd_Box aBox; + if (!aBox.FromString (aValue)) + continue; + + TopoDS_Shape aShape = VInspector_Tools::CreateShape (aBox); + aBuilder.Add (aCompound, aShape); + } + } + return aCompound; +} + +// ======================================================================= +// function : Dump +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemBVHTreeNode::Dump (Standard_OStream& OS) const +{ + opencascade::handle > aBVHTree = GetTree(); + if (aBVHTree.IsNull()) + return Standard_False; + + aBVHTree->DumpNode (Row(), OS); + return Standard_True; +} diff --git a/tools/VInspector/VInspector_ItemBVHTreeNode.hxx b/tools/VInspector/VInspector_ItemBVHTreeNode.hxx new file mode 100644 index 0000000000..d5aef7b4b9 --- /dev/null +++ b/tools/VInspector/VInspector_ItemBVHTreeNode.hxx @@ -0,0 +1,96 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemBVHTreeNode_H +#define VInspector_ItemBVHTreeNode_H + +#include +#include + +//#include +//#include + +class SelectMgr_BaseFrustum; + +class VInspector_ItemBVHTreeNode; +typedef QExplicitlySharedDataPointer VInspector_ItemBVHTreeNodePtr; + +//! \class VInspector_ItemBVHTreeNode +//! Parent item, that corresponds Folder under the AIS_InteractiveContext +//! Children of the item are: none +class VInspector_ItemBVHTreeNode : public VInspector_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemBVHTreeNodePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemBVHTreeNodePtr (new VInspector_ItemBVHTreeNode (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemBVHTreeNode() Standard_OVERRIDE {}; + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return NULL; } + + //! Returns parent tree, the node information is obtained from the tree by the given index + Standard_EXPORT opencascade::handle > GetTree() const; + + //! Dumps the content of me on the stream . + virtual Standard_Boolean Dump (Standard_OStream& OS) const; + +protected: + //! Initialize the current item. It is empty because Reset() is also empty. + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + + //! Build presentation shape + //! \return generated shape of the item parameters + virtual TopoDS_Shape buildPresentationShape() Standard_OVERRIDE; + +protected: + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! param theParent a parent item + //! \param theRow the item row positition in the parent item + //! \param theColumn the item column positition in the parent item + VInspector_ItemBVHTreeNode(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase(theParent, theRow, theColumn) {} + +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemContainer.cxx b/tools/VInspector/VInspector_ItemContainer.cxx new file mode 100644 index 0000000000..a72c4741c6 --- /dev/null +++ b/tools/VInspector/VInspector_ItemContainer.cxx @@ -0,0 +1,96 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemContainer::initValue (int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (Column() != 0 || (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole)) + return QVariant(); + + VInspector_ItemContainerAPI* aContainerItem = dynamic_cast(Parent().data()); + + if (!aContainerItem) + return "Empty item container"; + + return aContainerItem->GetContainerValue (Row(), theItemRole); +} + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemContainer::initRowCount() const +{ + VInspector_ItemContainerAPI* aContainerItem = dynamic_cast(Parent().data()); + + if (!aContainerItem) + return 0; + + return aContainerItem->GetContainerRowCount (Row()); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemContainer::createChild (int theRow, int theColumn) +{ + VInspector_ItemContainerAPI* aContainerItem = dynamic_cast(Parent().data()); + + if (!aContainerItem) + return TreeModel_ItemBasePtr(); + + return aContainerItem->CreateContainerChild (currentItem(), Row(), theRow, theColumn); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void VInspector_ItemContainer::Init() +{ + TreeModel_ItemBase::Init(); // to use getIO() without circling initialization +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemContainer::Reset() +{ + VInspector_ItemBase::Reset(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void VInspector_ItemContainer::initItem() const +{ + if (IsInitialized()) + return; + const_cast (this)->Init(); +} diff --git a/tools/VInspector/VInspector_ItemContainer.hxx b/tools/VInspector/VInspector_ItemContainer.hxx new file mode 100644 index 0000000000..f71949bc0c --- /dev/null +++ b/tools/VInspector/VInspector_ItemContainer.hxx @@ -0,0 +1,87 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemContainer_H +#define VInspector_ItemContainer_H + +#include +#include + +#include +#include +#include + +class Prs3d_Drawer; + +class QItemSelectionModel; + +class VInspector_ItemContainer; +typedef QExplicitlySharedDataPointer VInspector_ItemContainerPtr; + +//! \class VInspector_ItemContainer +//! Item presents additional level of information in the tree model. +//! Parent is item context, children are either folder item or Selection filter item. +class VInspector_ItemContainer : public VInspector_ItemBase +{ + +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemContainerPtr CreateItem (TreeModel_ItemBasePtr theParent, + const int theRow, const int theColumn) + { return VInspector_ItemContainerPtr (new VInspector_ItemContainer (theParent, theRow, theColumn)); } + //! Destructor + virtual ~VInspector_ItemContainer() Standard_OVERRIDE {}; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { return NULL; } + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + +protected: + + //! Initialize the current item. It is empty because Reset() is also empty. + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of item selected + //! \return rows count + virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! param theParent a parent item + VInspector_ItemContainer (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase (theParent, theRow, theColumn) {} + +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemContainerAPI.hxx b/tools/VInspector/VInspector_ItemContainerAPI.hxx new file mode 100644 index 0000000000..c986433e2b --- /dev/null +++ b/tools/VInspector/VInspector_ItemContainerAPI.hxx @@ -0,0 +1,50 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemContainerAPI_H +#define VInspector_ItemContainerAPI_H + +#include +#include + +//! \class VInspector_ItemContainerAPI +class VInspector_ItemContainerAPI +{ + +public: + //! Constructor + VInspector_ItemContainerAPI () {} + + //! Destructor + virtual ~VInspector_ItemContainerAPI() {}; + + //! Returns number of item selected + //! \return rows count + virtual int GetContainerRowCount (const int theContainerRow) const = 0; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + virtual QVariant GetContainerValue (const int theContainerRow, const int theItemRole) const = 0; + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr CreateContainerChild (const TreeModel_ItemBasePtr& theParent, const int theContainerRow, int theRow, int theColumn) = 0; + +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemOpenGlContext.cxx b/tools/VInspector/VInspector_ItemOpenGlContext.cxx new file mode 100644 index 0000000000..6a83dd0d81 --- /dev/null +++ b/tools/VInspector/VInspector_ItemOpenGlContext.cxx @@ -0,0 +1,216 @@ +// Created on: 2019-03-15 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +//#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlContext::Init() +{ + //VInspector_ItemOpenGlContextListPtr aParentItem = itemDynamicCast(Parent()); + //myLayer = aParentItem->GetLayer (Row(), myLayerId); + + TreeModel_ItemBase::Init(); +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlContext::Reset() +{ + VInspector_ItemBase::Reset(); + myLayer = NULL; +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlContext::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemOpenGlContext::initRowCount() const +{ + if (Column() != 0) + return 0; + + return 0; +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlContext::initValue (const int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + Handle(OpenGl_Layer) aLayer = GetLayer(); + if (aLayer.IsNull()) + return Column() == 0 ? "Empty element" : ""; + + switch (Column()) + { + case 0: + { + TCollection_AsciiString aLayerId = Graphic3d::ZLayerIdToString (myLayerId); + if (aLayerId.IsEmpty()) + aLayerId = TCollection_AsciiString (myLayerId); + return theItemRole == Qt::ToolTipRole ? QVariant ("") + : QVariant (QString("%1 (%2)") + .arg(aLayer->DynamicType()->Name()) + .arg (aLayerId.ToCString())); + } + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : GetTableRowCount +// purpose : +// ======================================================================= +int VInspector_ItemOpenGlContext::GetTableRowCount() const +{ + return 40; +} + +// ======================================================================= +// function : GetTableData +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlContext::GetTableData (const int theRow, const int theColumn, const int theRole) const +{ + if (theRole != Qt::DisplayRole) + return QVariant(); + + Handle(OpenGl_Layer) aLayer = GetLayer(); + if (aLayer.IsNull()) + return QVariant(); + + bool isFirstColumn = theColumn == 0; + + switch (theRow) + { + case 0: return isFirstColumn ? QVariant ("NbStructures") : QVariant (aLayer->NbStructures()); + case 1: return isFirstColumn ? QVariant ("NbStructuresNotCulled") : QVariant (aLayer->NbStructuresNotCulled()); + case 2: return isFirstColumn ? QVariant ("NbPriorities") : QVariant (aLayer->NbPriorities()); + + case 3: return isFirstColumn ? QVariant ("ArrayOfStructures") : QVariant (aLayer->ArrayOfStructures().Size()); + case 4: return isFirstColumn ? QVariant ("IsCulled") : QVariant (aLayer->IsCulled()); + case 5: return isFirstColumn ? QVariant ("NbOfTransformPersistenceObjects") : QVariant (aLayer->NbOfTransformPersistenceObjects()); + + case 6: return isFirstColumn ? QVariant ("CullableStructuresBVH") : QVariant (aLayer->CullableStructuresBVH().Size()); + case 7: return isFirstColumn ? QVariant ("CullableTrsfPersStructuresBVH") : QVariant (aLayer->CullableTrsfPersStructuresBVH().Size()); + case 8: return isFirstColumn ? QVariant ("NonCullableStructures") : QVariant (aLayer->NonCullableStructures().Size()); + + default: + break; + } + + Standard_Integer aRow = theRow - 9; + return getLayerSettingsTableData (aRow, theColumn, theRole, aLayer->LayerSettings()); +} + +// ======================================================================= +// function : getLayerSettingsTableData +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlContext::getLayerSettingsTableData (const int theRow, const int theColumn, const int theRole, + const Graphic3d_ZLayerSettings& theSettings) const +{ + bool isFirstColumn = theColumn == 0; + + switch (theRow) + { + case 0: return isFirstColumn ? QVariant ("LayerSettings:") : QVariant(); + case 1: return isFirstColumn ? QVariant ("Name") : QVariant (theSettings.Name().ToCString()); + case 2: return isFirstColumn ? QVariant ("Lights") : QVariant (ViewControl_Tools::GetPointerInfo (theSettings.Lights()).ToCString()); + + case 3: return isFirstColumn ? QVariant ("Origin") : QVariant (ViewControl_Tools::ToString (theSettings.Origin()).ToCString()); + case 4: return isFirstColumn ? QVariant ("OriginTransformation") + : QVariant (ViewControl_Tools::ToString (theSettings.OriginTransformation()).ToCString()); + + case 5: return isFirstColumn ? QVariant ("HasCullingDistance") : QVariant (theSettings.HasCullingDistance()); + case 6: return isFirstColumn ? QVariant ("CullingDistance") + : QVariant (theSettings.HasCullingDistance() ? theSettings.CullingDistance() : 0); + + case 7: return isFirstColumn ? QVariant ("HasCullingSize") : QVariant (theSettings.HasCullingSize()); + case 8: return isFirstColumn ? QVariant ("CullingSize") + : QVariant (theSettings.HasCullingSize() ? theSettings.CullingSize() : 0); + + case 9: return isFirstColumn ? QVariant ("IsImmediate") : QVariant (theSettings.IsImmediate()); + case 10: return isFirstColumn ? QVariant ("UseEnvironmentTexture") : QVariant (theSettings.UseEnvironmentTexture()); + case 11: return isFirstColumn ? QVariant ("ToEnableDepthTest") : QVariant (theSettings.ToEnableDepthTest()); + case 12: return isFirstColumn ? QVariant ("ToEnableDepthWrite") : QVariant (theSettings.ToEnableDepthWrite()); + case 13: return isFirstColumn ? QVariant ("ToClearDepth") : QVariant (theSettings.ToClearDepth()); + case 14: return isFirstColumn ? QVariant ("ToRenderInDepthPrepass") : QVariant (theSettings.ToRenderInDepthPrepass()); + + case 15: return isFirstColumn ? QVariant ("PolygonOffset: Mode") + : QVariant (Aspect::PolygonOffsetModeToString (theSettings.PolygonOffset().Mode)); + case 16: return isFirstColumn ? QVariant ("PolygonOffset: Factor") : QVariant (theSettings.PolygonOffset().Factor); + case 17: return isFirstColumn ? QVariant ("PolygonOffset: Units") : QVariant (theSettings.PolygonOffset().Units); + + default: break; + } + return QVariant(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemOpenGlContext::createChild (int theRow, int theColumn) +{ + (void)theRow; + (void)theColumn; + return TreeModel_ItemBasePtr(); +} diff --git a/tools/VInspector/VInspector_ItemOpenGlContext.hxx b/tools/VInspector/VInspector_ItemOpenGlContext.hxx new file mode 100644 index 0000000000..1f9d2e2b1f --- /dev/null +++ b/tools/VInspector/VInspector_ItemOpenGlContext.hxx @@ -0,0 +1,110 @@ +// Created on: 2019-03-15 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemOpenGlContext_H +#define VInspector_ItemOpenGlContext_H + +#include +#include + +#include +#include + +class Graphic3d_Group; + +class VInspector_ItemOpenGlContext; +typedef QExplicitlySharedDataPointer VInspector_ItemOpenGlContextPtr; + +//! \class VInspector_ItemOpenGlContext +//! Parent item, that corresponds to AIS_InteractiveContext +//! Children of the item are: +//! - "Property" item to show context attributes such as selection filters and drawer properties +//! - presentation items to show all interactive elements displayed/erased in the context +class VInspector_ItemOpenGlContext : public VInspector_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemOpenGlContextPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemOpenGlContextPtr (new VInspector_ItemOpenGlContext (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemOpenGlContext() Standard_OVERRIDE {}; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return myLayer; } + + //! Returns the current graphic3d group, init item if it was not initialized yet + //! \return graphic group + Standard_EXPORT Handle(OpenGl_Layer) GetLayer() const + { return Handle(OpenGl_Layer)::DownCast (GetObject());} + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns number of table rows + //! \return an integer value + virtual int GetTableRowCount() const Standard_OVERRIDE; + + //! Returns table value for the row in form: + //! \param theRow a model index row + //! \param theColumn a model index column + virtual QVariant GetTableData (const int theRow, const int theColumn, const int theRole) const Standard_OVERRIDE; + +protected: + + //! Initialize the current item. It creates a backup of the specific item information + //! Do nothing as context has been already set into item + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + +protected: + //! Returns table presentation of layer settings + QVariant getLayerSettingsTableData (const int theRow, const int theColumn, const int theRole, + const Graphic3d_ZLayerSettings& theSettings) const; + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! param theParent a parent item + //! \param theRow the item row positition in the parent item + //! \param theColumn the item column positition in the parent item + VInspector_ItemOpenGlContext(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase(theParent, theRow, theColumn) {} + +private: + Handle(OpenGl_Layer) myLayer; //! current layer + Graphic3d_ZLayerId myLayerId; //! current Z layer index in OpenGl_View +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemOpenGlWindow.cxx b/tools/VInspector/VInspector_ItemOpenGlWindow.cxx new file mode 100644 index 0000000000..a8d9063e57 --- /dev/null +++ b/tools/VInspector/VInspector_ItemOpenGlWindow.cxx @@ -0,0 +1,216 @@ +// Created on: 2019-03-15 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +//#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlWindow::Init() +{ + //VInspector_ItemOpenGlWindowListPtr aParentItem = itemDynamicCast(Parent()); + //myLayer = aParentItem->GetLayer (Row(), myLayerId); + + TreeModel_ItemBase::Init(); +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlWindow::Reset() +{ + VInspector_ItemBase::Reset(); + myLayer = NULL; +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void VInspector_ItemOpenGlWindow::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemOpenGlWindow::initRowCount() const +{ + if (Column() != 0) + return 0; + + return 0; +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlWindow::initValue (const int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + Handle(OpenGl_Layer) aLayer = GetLayer(); + if (aLayer.IsNull()) + return Column() == 0 ? "Empty element" : ""; + + switch (Column()) + { + case 0: + { + TCollection_AsciiString aLayerId = Graphic3d::ZLayerIdToString (myLayerId); + if (aLayerId.IsEmpty()) + aLayerId = TCollection_AsciiString (myLayerId); + return theItemRole == Qt::ToolTipRole ? QVariant ("") + : QVariant (QString("%1 (%2)") + .arg(aLayer->DynamicType()->Name()) + .arg (aLayerId.ToCString())); + } + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : GetTableRowCount +// purpose : +// ======================================================================= +int VInspector_ItemOpenGlWindow::GetTableRowCount() const +{ + return 40; +} + +// ======================================================================= +// function : GetTableData +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlWindow::GetTableData (const int theRow, const int theColumn, const int theRole) const +{ + if (theRole != Qt::DisplayRole) + return QVariant(); + + Handle(OpenGl_Layer) aLayer = GetLayer(); + if (aLayer.IsNull()) + return QVariant(); + + bool isFirstColumn = theColumn == 0; + + switch (theRow) + { + case 0: return isFirstColumn ? QVariant ("NbStructures") : QVariant (aLayer->NbStructures()); + case 1: return isFirstColumn ? QVariant ("NbStructuresNotCulled") : QVariant (aLayer->NbStructuresNotCulled()); + case 2: return isFirstColumn ? QVariant ("NbPriorities") : QVariant (aLayer->NbPriorities()); + + case 3: return isFirstColumn ? QVariant ("ArrayOfStructures") : QVariant (aLayer->ArrayOfStructures().Size()); + case 4: return isFirstColumn ? QVariant ("IsCulled") : QVariant (aLayer->IsCulled()); + case 5: return isFirstColumn ? QVariant ("NbOfTransformPersistenceObjects") : QVariant (aLayer->NbOfTransformPersistenceObjects()); + + case 6: return isFirstColumn ? QVariant ("CullableStructuresBVH") : QVariant (aLayer->CullableStructuresBVH().Size()); + case 7: return isFirstColumn ? QVariant ("CullableTrsfPersStructuresBVH") : QVariant (aLayer->CullableTrsfPersStructuresBVH().Size()); + case 8: return isFirstColumn ? QVariant ("NonCullableStructures") : QVariant (aLayer->NonCullableStructures().Size()); + + default: + break; + } + + Standard_Integer aRow = theRow - 9; + return getLayerSettingsTableData (aRow, theColumn, theRole, aLayer->LayerSettings()); +} + +// ======================================================================= +// function : getLayerSettingsTableData +// purpose : +// ======================================================================= +QVariant VInspector_ItemOpenGlWindow::getLayerSettingsTableData (const int theRow, const int theColumn, const int theRole, + const Graphic3d_ZLayerSettings& theSettings) const +{ + bool isFirstColumn = theColumn == 0; + + switch (theRow) + { + case 0: return isFirstColumn ? QVariant ("LayerSettings:") : QVariant(); + case 1: return isFirstColumn ? QVariant ("Name") : QVariant (theSettings.Name().ToCString()); + case 2: return isFirstColumn ? QVariant ("Lights") : QVariant (ViewControl_Tools::GetPointerInfo (theSettings.Lights()).ToCString()); + + case 3: return isFirstColumn ? QVariant ("Origin") : QVariant (ViewControl_Tools::ToString (theSettings.Origin()).ToCString()); + case 4: return isFirstColumn ? QVariant ("OriginTransformation") + : QVariant (ViewControl_Tools::ToString (theSettings.OriginTransformation()).ToCString()); + + case 5: return isFirstColumn ? QVariant ("HasCullingDistance") : QVariant (theSettings.HasCullingDistance()); + case 6: return isFirstColumn ? QVariant ("CullingDistance") + : QVariant (theSettings.HasCullingDistance() ? theSettings.CullingDistance() : 0); + + case 7: return isFirstColumn ? QVariant ("HasCullingSize") : QVariant (theSettings.HasCullingSize()); + case 8: return isFirstColumn ? QVariant ("CullingSize") + : QVariant (theSettings.HasCullingSize() ? theSettings.CullingSize() : 0); + + case 9: return isFirstColumn ? QVariant ("IsImmediate") : QVariant (theSettings.IsImmediate()); + case 10: return isFirstColumn ? QVariant ("UseEnvironmentTexture") : QVariant (theSettings.UseEnvironmentTexture()); + case 11: return isFirstColumn ? QVariant ("ToEnableDepthTest") : QVariant (theSettings.ToEnableDepthTest()); + case 12: return isFirstColumn ? QVariant ("ToEnableDepthWrite") : QVariant (theSettings.ToEnableDepthWrite()); + case 13: return isFirstColumn ? QVariant ("ToClearDepth") : QVariant (theSettings.ToClearDepth()); + case 14: return isFirstColumn ? QVariant ("ToRenderInDepthPrepass") : QVariant (theSettings.ToRenderInDepthPrepass()); + + case 15: return isFirstColumn ? QVariant ("PolygonOffset: Mode") + : QVariant (Aspect::PolygonOffsetModeToString (theSettings.PolygonOffset().Mode)); + case 16: return isFirstColumn ? QVariant ("PolygonOffset: Factor") : QVariant (theSettings.PolygonOffset().Factor); + case 17: return isFirstColumn ? QVariant ("PolygonOffset: Units") : QVariant (theSettings.PolygonOffset().Units); + + default: break; + } + return QVariant(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemOpenGlWindow::createChild (int theRow, int theColumn) +{ + (void)theRow; + (void)theColumn; + return TreeModel_ItemBasePtr(); +} diff --git a/tools/VInspector/VInspector_ItemOpenGlWindow.hxx b/tools/VInspector/VInspector_ItemOpenGlWindow.hxx new file mode 100644 index 0000000000..bcc6f46a0c --- /dev/null +++ b/tools/VInspector/VInspector_ItemOpenGlWindow.hxx @@ -0,0 +1,110 @@ +// Created on: 2019-03-15 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemOpenGlWindow_H +#define VInspector_ItemOpenGlWindow_H + +#include +#include + +#include +#include + +class Graphic3d_Group; + +class VInspector_ItemOpenGlWindow; +typedef QExplicitlySharedDataPointer VInspector_ItemOpenGlWindowPtr; + +//! \class VInspector_ItemOpenGlWindow +//! Parent item, that corresponds to AIS_InteractiveContext +//! Children of the item are: +//! - "Property" item to show context attributes such as selection filters and drawer properties +//! - presentation items to show all interactive elements displayed/erased in the context +class VInspector_ItemOpenGlWindow : public VInspector_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemOpenGlWindowPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemOpenGlWindowPtr (new VInspector_ItemOpenGlWindow (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemOpenGlWindow() Standard_OVERRIDE {}; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return myLayer; } + + //! Returns the current graphic3d group, init item if it was not initialized yet + //! \return graphic group + Standard_EXPORT Handle(OpenGl_Layer) GetLayer() const + { return Handle(OpenGl_Layer)::DownCast (GetObject());} + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns number of table rows + //! \return an integer value + virtual int GetTableRowCount() const Standard_OVERRIDE; + + //! Returns table value for the row in form: + //! \param theRow a model index row + //! \param theColumn a model index column + virtual QVariant GetTableData (const int theRow, const int theColumn, const int theRole) const Standard_OVERRIDE; + +protected: + + //! Initialize the current item. It creates a backup of the specific item information + //! Do nothing as context has been already set into item + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + +protected: + //! Returns table presentation of layer settings + QVariant getLayerSettingsTableData (const int theRow, const int theColumn, const int theRole, + const Graphic3d_ZLayerSettings& theSettings) const; + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! param theParent a parent item + //! \param theRow the item row positition in the parent item + //! \param theColumn the item column positition in the parent item + VInspector_ItemOpenGlWindow(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase(theParent, theRow, theColumn) {} + +private: + Handle(OpenGl_Layer) myLayer; //! current layer + Graphic3d_ZLayerId myLayerId; //! current Z layer index in OpenGl_View +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemSelectBasicsEntityOwner.cxx b/tools/VInspector/VInspector_ItemSelectBasicsEntityOwner.cxx index 312a658c8a..edcde81111 100644 --- a/tools/VInspector/VInspector_ItemSelectBasicsEntityOwner.cxx +++ b/tools/VInspector/VInspector_ItemSelectBasicsEntityOwner.cxx @@ -215,20 +215,23 @@ QVariant VInspector_ItemSelectBasicsEntityOwner::GetTableData(const int theRow, bool isFirstColumn = theColumn == 0; Handle(SelectBasics_EntityOwner) anOwner = getEntityOwner(); + Handle(SelectMgr_EntityOwner) anEntityOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwner); switch (theRow) { case 0: return isFirstColumn ? QVariant ("Priority") : QVariant (anOwner->Priority()); case 1: return isFirstColumn ? QVariant ("HasLocation") : QVariant (anOwner->HasLocation()); case 2: return isFirstColumn ? QVariant ("Location") : (anOwner->HasLocation() ? QVariant (ViewControl_Tools::ToString (anOwner->Location()).ToCString()) : QVariant()); + case 3: return isFirstColumn ? QVariant ("IsSelected") : QVariant (!anEntityOwner.IsNull() ? anEntityOwner->IsSelected() : ""); default: break; } + Handle(StdSelect_BRepOwner) aBROwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner); if (aBROwner.IsNull()) return QVariant(); - int aBRepOwnerRow = theRow - 3; + int aBRepOwnerRow = theRow - 4; switch (aBRepOwnerRow) { case 0: return ViewControl_Table::SeparatorData(); diff --git a/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.cxx b/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.cxx index e602f2b733..73e7dc02db 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.cxx +++ b/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.cxx @@ -103,6 +103,21 @@ void VInspector_ItemSelectMgrBaseFrustum::initItem() const const_cast(this)->Init(); } +// ======================================================================= +// function : Dump +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemSelectMgrBaseFrustum::Dump (Standard_OStream& OS) const +{ + Handle(SelectMgr_BaseFrustum) aFrustum = GetFrustum(); + + if (aFrustum.IsNull()) + return Standard_False; + + aFrustum->Dump (OS); + return Standard_True; +} + // ======================================================================= // function : GetTableRowCount // purpose : diff --git a/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.hxx b/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.hxx index 39079ddccf..37393debee 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.hxx +++ b/tools/VInspector/VInspector_ItemSelectMgrBaseFrustum.hxx @@ -53,6 +53,9 @@ public: Standard_EXPORT Handle(SelectMgr_BaseFrustum) GetFrustum() const { return Handle(SelectMgr_BaseFrustum)::DownCast (GetObject()); } + //! Dumps the content of me on the stream . + virtual Standard_Boolean Dump (Standard_OStream& OS) const; + protected: //! Initialize the current item. It is empty because Reset() is also empty. virtual void initItem() const Standard_OVERRIDE; diff --git a/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.cxx b/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.cxx new file mode 100644 index 0000000000..8f2051acb5 --- /dev/null +++ b/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.cxx @@ -0,0 +1,188 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include + +#include + +#include + +// ======================================================================= +// function : initRowCount +// purpose : +// ======================================================================= +int VInspector_ItemSelectMgrSelectableObjectSet::initRowCount() const +{ + if (Column() != 0) + return 0; + + return SelectMgr_SelectableObjectSet::BVHSubsetNb; // VInspector_ItemBVHTree items +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemSelectMgrSelectableObjectSet::initValue (const int theItemRole) const +{ + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + SelectMgr_SelectableObjectSet aSet; + if (!GetSelectableObjectSet (aSet)) + return Column() == 0 ? "Empty selectable object set" : ""; + + switch (Column()) + { + case 0: return "SelectMgr_SelectableObjectSet"; + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= + +void VInspector_ItemSelectMgrSelectableObjectSet::Init() +{ + //VInspector_ItemFolderObjectPtr aParentItem = itemDynamicCast(Parent()); + //Handle(SelectMgr_SelectingVolumeManager) aVolumeMgr; + //if (aParentItem) + //{ + // VInspector_ItemContextPtr aParentContextItem = itemDynamicCast(aParentItem->Parent()); + // if (aParentContextItem) + // { + // Handle(AIS_InteractiveContext) aContext = aParentContextItem->GetContext(); + // aVolumeMgr = aContext->MainSelector(); + // } + //} + //setViewerSelector (aVolumeMgr); + + //UpdatePresentationShape(); + TreeModel_ItemBase::Init(); // to use getIO() without circling initialization +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= + +void VInspector_ItemSelectMgrSelectableObjectSet::Reset() +{ + VInspector_ItemBase::Reset(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= + +void VInspector_ItemSelectMgrSelectableObjectSet::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : GetSelectableObjectSet +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemSelectMgrSelectableObjectSet::GetSelectableObjectSet (SelectMgr_SelectableObjectSet& theSet) const +{ + VInspector_ItemSelectMgrViewerSelectorPtr aParentItem = itemDynamicCast(Parent()); + + if (!aParentItem || aParentItem->GetViewerSelector().IsNull()) + return Standard_False; + + theSet = aParentItem->GetViewerSelector()->GetSelectableObjects(); + return Standard_True; +} + +// ======================================================================= +// function : GetBVHTree +// purpose : +// ======================================================================= +opencascade::handle > VInspector_ItemSelectMgrSelectableObjectSet::GetBVHTree (const int theRow, + TCollection_AsciiString& theName) const +{ + SelectMgr_SelectableObjectSet aSet; + if (!GetSelectableObjectSet (aSet)) + return NULL; + + if (theRow >= SelectMgr_SelectableObjectSet::BVHSubsetNb) + return NULL; + + SelectMgr_SelectableObjectSet::BVHSubset aBVHSubset = (SelectMgr_SelectableObjectSet::BVHSubset)theRow; + theName = TCollection_AsciiString ("BVH_Tree_") + SelectMgr::BVHSubsetToString (aBVHSubset); + + return aSet.BVH (aBVHSubset); +} + +// ======================================================================= +// function : GetTableRowCount +// purpose : +// ======================================================================= +int VInspector_ItemSelectMgrSelectableObjectSet::GetTableRowCount() const +{ + return 60; +} + +// ======================================================================= +// function : GetTableData +// purpose : +// ======================================================================= +QVariant VInspector_ItemSelectMgrSelectableObjectSet::GetTableData (const int theRow, const int theColumn, const int theRole) const +{ + if (theRole != Qt::DisplayRole) + return QVariant(); + + //SelectMgr_SelectingVolumeManager aVolumeMgr; + //if (!GetViewerSelector (aVolumeMgr)) + // return QVariant(); + + //bool isFirstColumn = theColumn == 0; + //switch (theRow) + //{ + // case 0: return isFirstColumn ? QVariant ("GetActiveSelectionType") : QVariant (aVolumeMgr.GetActiveSelectionType()); + // case 1: return isFirstColumn ? QVariant ("IsOverlapAllowed()") : QVariant (aVolumeMgr.IsOverlapAllowed()); + // case 2: return isFirstColumn ? "GetNearPickedPnt" : ViewControl_Tools::ToString (aVolumeMgr.GetNearPickedPnt()).ToCString(); + // case 3: return isFirstColumn ? "GetFarPickedPnt" : ViewControl_Tools::ToString (aVolumeMgr.GetFarPickedPnt()).ToCString(); + // default: break; + //} + return QVariant(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemSelectMgrSelectableObjectSet::createChild (int theRow, int theColumn) +{ + if (theRow == 0 || theRow == 1 || theRow == 2) + return VInspector_ItemBVHTree::CreateItem (currentItem(), theRow, theColumn); + return TreeModel_ItemBasePtr(); +} diff --git a/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.hxx b/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.hxx new file mode 100644 index 0000000000..9a6a575d23 --- /dev/null +++ b/tools/VInspector/VInspector_ItemSelectMgrSelectableObjectSet.hxx @@ -0,0 +1,102 @@ +// Created on: 2019-04-29 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemSelectMgrSelectableObjectSet_H +#define VInspector_ItemSelectMgrSelectableObjectSet_H + +#include + +#include +#include +#include +#include + +class SelectMgr_BaseFrustum; + +class VInspector_ItemSelectMgrSelectableObjectSet; +typedef QExplicitlySharedDataPointer VInspector_ItemSelectMgrSelectableObjectSetPtr; + +//! \class VInspector_ItemSelectMgrSelectableObjectSet +//! Parent item, that corresponds Folder under the AIS_InteractiveContext +//! Children of the item are: none +class VInspector_ItemSelectMgrSelectableObjectSet : public VInspector_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemSelectMgrSelectableObjectSetPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemSelectMgrSelectableObjectSetPtr (new VInspector_ItemSelectMgrSelectableObjectSet (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemSelectMgrSelectableObjectSet() Standard_OVERRIDE {}; + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return NULL; } + + //! Returns current drawer, initialize the drawer if it was not initialized yet + Standard_EXPORT Standard_Boolean GetSelectableObjectSet (SelectMgr_SelectableObjectSet& theSet) const; + + //! Returns child BVH tree of the row + opencascade::handle > GetBVHTree (const int theRow, TCollection_AsciiString& theName) const; + +protected: + //! Initialize the current item. It is empty because Reset() is also empty. + virtual void initItem() const Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + + //! Returns number of table rows + //! \return an integer value + virtual int GetTableRowCount() const Standard_OVERRIDE; + + //! Returns table value for the row in form: + //! \param theRow a model index row + //! \param theColumn a model index column + virtual QVariant GetTableData (const int theRow, const int theColumn, const int theRole) const Standard_OVERRIDE; + +protected: + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! param theParent a parent item + //! \param theRow the item row positition in the parent item + //! \param theColumn the item column positition in the parent item + VInspector_ItemSelectMgrSelectableObjectSet(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase(theParent, theRow, theColumn) {} + +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.cxx b/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.cxx index 8a08b48878..3f89dec684 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.cxx +++ b/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.cxx @@ -29,7 +29,7 @@ int VInspector_ItemSelectMgrSelectingVolumeManager::initRowCount() const if (Column() != 0) return 0; - return 1; + return 2; } // ======================================================================= @@ -119,6 +119,24 @@ Standard_Boolean VInspector_ItemSelectMgrSelectingVolumeManager::GetViewerSelect return Standard_True; } +// ======================================================================= +// function : GetTableRowCount +// purpose : +// ======================================================================= +Handle(SelectMgr_BaseFrustum) VInspector_ItemSelectMgrSelectingVolumeManager::GetFrustum (const int theRow) const +{ + SelectMgr_SelectingVolumeManager aVolumeManager; + if (!GetViewerSelector (aVolumeManager)) + return NULL; + + if (theRow == 0) + return aVolumeManager.GetVolume (SelectBasics_SelectingVolumeManager::Box); + else if (theRow == 1) + return aVolumeManager.GetVolume (SelectBasics_SelectingVolumeManager::Polyline); + + return NULL; +} + // ======================================================================= // function : GetTableRowCount // purpose : @@ -159,7 +177,7 @@ QVariant VInspector_ItemSelectMgrSelectingVolumeManager::GetTableData (const int // ======================================================================= TreeModel_ItemBasePtr VInspector_ItemSelectMgrSelectingVolumeManager::createChild (int theRow, int theColumn) { - if (theRow == 0) + if (theRow == 0 || theRow == 1) return VInspector_ItemSelectMgrBaseFrustum::CreateItem (currentItem(), theRow, theColumn); //else if (theRow == 1) // return VInspector_ItemAspectWindow::CreateItem (currentItem(), theRow, theColumn); diff --git a/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.hxx b/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.hxx index b08765e477..b0f4a94b8a 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.hxx +++ b/tools/VInspector/VInspector_ItemSelectMgrSelectingVolumeManager.hxx @@ -22,6 +22,8 @@ #include #include +class SelectMgr_BaseFrustum; + class VInspector_ItemSelectMgrSelectingVolumeManager; typedef QExplicitlySharedDataPointer VInspector_ItemSelectMgrSelectingVolumeManagerPtr; @@ -52,6 +54,9 @@ public: //! Returns current drawer, initialize the drawer if it was not initialized yet Standard_EXPORT Standard_Boolean GetViewerSelector (SelectMgr_SelectingVolumeManager& theVolumeManager) const; + //! Returns frustum Frustum for row = 0, FrustumSet for row = 1 + Handle(SelectMgr_BaseFrustum) GetFrustum (const int theRow) const; + protected: //! Initialize the current item. It is empty because Reset() is also empty. virtual void initItem() const Standard_OVERRIDE; diff --git a/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.cxx b/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.cxx new file mode 100644 index 0000000000..672a946a53 --- /dev/null +++ b/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.cxx @@ -0,0 +1,157 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + + +#include +#include +#include +#include + +#include +#include + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +int VInspector_ItemSelectMgrSensitiveEntitySet::initRowCount() const +{ + //Handle(SelectMgr_SensitiveEntitySet) aSensitiveSet = Handle(SelectMgr_SensitiveEntitySet)::DownCast (GetSensitiveEntitySet()); + //if (!aSensitiveSet.IsNull()) + // return aSensitiveSet->Size(); + + return 1; // for BVH_Tree +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemSelectMgrSensitiveEntitySet::initValue (int theItemRole) const +{ + if (theItemRole == Qt::DisplayRole && theItemRole == Qt::ToolTipRole && Column() == 2) + return ViewControl_Tools::GetPointerInfo (GetSelectableObject(), true).ToCString(); + + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + Handle(SelectMgr_SensitiveEntitySet) anEntitySet = GetSensitiveEntitySet(); + const Handle(SelectMgr_SelectableObject)& aSelectableObject = GetSelectableObject(); + + if (anEntitySet.IsNull()) + return Column() == 0 ? "Empty sensitive entity set" : ""; + + if (aSelectableObject.IsNull()) + return Column() == 0 ? "Empty selectable object for sensitive entity set" : ""; + + switch (theItemRole) + { + case Qt::DisplayRole: + case Qt::EditRole: + case Qt::ToolTipRole: + { + switch (Column()) + { + case 0: return aSelectableObject->DynamicType()->Name(); + default: + break; + } + break; + } + default: + break; + } + return QVariant(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr VInspector_ItemSelectMgrSensitiveEntitySet::createChild (int theRow, int theColumn) +{ + return VInspector_ItemBVHTree::CreateItem (currentItem(), theRow, theColumn); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void VInspector_ItemSelectMgrSensitiveEntitySet::Init() +{ + VInspector_ItemSelectMgrViewerSelectorPtr aParentItem = itemDynamicCast(Parent()->Parent()); + + Handle(SelectMgr_SelectableObject) anObject; + Handle(SelectMgr_SensitiveEntitySet) anEntitySet = aParentItem->GetSensitiveEntitySet (Row(), anObject); + + myEntitySet = anEntitySet; + mySelectableObject = anObject; + + UpdatePresentationShape(); + TreeModel_ItemBase::Init(); +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemSelectMgrSensitiveEntitySet::Reset() +{ + // an empty method to don't clear the main label, otherwise the model will be empty + TreeModel_ItemBase::Reset(); + myEntitySet = NULL; + mySelectableObject = NULL; +} + +// ======================================================================= +// function : GetBVHTree +// purpose : +// ======================================================================= +opencascade::handle > VInspector_ItemSelectMgrSensitiveEntitySet::GetBVHTree (const int theRow, + TCollection_AsciiString& theName) const +{ + Handle(SelectMgr_SensitiveEntitySet) anEntitySet = GetSensitiveEntitySet(); + + if (anEntitySet.IsNull()) + return NULL; + + return anEntitySet->BVH(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void VInspector_ItemSelectMgrSensitiveEntitySet::initItem() const +{ + if (IsInitialized()) + return; + + const_cast(this)->Init(); +} + +// ======================================================================= +// function : buildPresentationShape +// purpose : +// ======================================================================= +TopoDS_Shape VInspector_ItemSelectMgrSensitiveEntitySet::buildPresentationShape() +{ + //mySelectableObject + return TopoDS_Shape(); +} diff --git a/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.hxx b/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.hxx new file mode 100644 index 0000000000..305417778b --- /dev/null +++ b/tools/VInspector/VInspector_ItemSelectMgrSensitiveEntitySet.hxx @@ -0,0 +1,112 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_ItemSelectMgrSensitiveEntitySet_H +#define VInspector_ItemSelectMgrSensitiveEntitySet_H + +#include +#include +#include +#include +#include + +class SelectMgr_SelectableObject; + +class QItemSelectionModel; +class VInspector_ItemSelectMgrSensitiveEntitySet; + +typedef QExplicitlySharedDataPointer VInspector_ItemSelectMgrSensitiveEntitySetPtr; + +//! \class VInspector_ItemSelectMgrSensitiveEntitySet +class VInspector_ItemSelectMgrSensitiveEntitySet : public VInspector_ItemBase +{ + +public: + + //! Creates an item wrapped by a shared pointer + static VInspector_ItemSelectMgrSensitiveEntitySetPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return VInspector_ItemSelectMgrSensitiveEntitySetPtr (new VInspector_ItemSelectMgrSensitiveEntitySet (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~VInspector_ItemSelectMgrSensitiveEntitySet() Standard_OVERRIDE {}; + + //! Returns data object of the item. + //! \return object + virtual Handle(Standard_Transient) GetObject() const { initItem(); return myEntitySet; } + + //! \return the current sensitive entity + Standard_EXPORT Handle(SelectMgr_SensitiveEntitySet) GetSensitiveEntitySet() const + { return Handle(SelectMgr_SensitiveEntitySet)::DownCast (GetObject()); } + + //! \return the current sensitive entity + Standard_EXPORT const Handle(SelectMgr_SelectableObject)& GetSelectableObject() const + { GetObject(); return mySelectableObject; } + + //! Inits the item, fills internal containers + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets cached values + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns child BVH tree of the row + opencascade::handle > GetBVHTree (const int theRow, TCollection_AsciiString& theName) const; + +protected: + + //! Initialize the current item. It is empty because Reset() is also empty. + virtual void initItem() const Standard_OVERRIDE; + + //! \return number of children. + virtual int initRowCount() const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + +protected: + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + + //! Returns table value for the row in form: depending on the aspect kind + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theEntityKind kind or kind of entity + QVariant getTableData (const int theRow, + const int theColumn, + const int theRole, + const TCollection_AsciiString& theEntityKind) const; + +protected: + //! Build presentation shape + //! \return generated shape of the item parameters + virtual TopoDS_Shape buildPresentationShape() Standard_OVERRIDE; + + //! Constructor + //! param theParent a parent item + VInspector_ItemSelectMgrSensitiveEntitySet(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : VInspector_ItemBase(theParent, theRow, theColumn) {} + +private: + + Handle(SelectMgr_SensitiveEntitySet) myEntitySet; //!< the current sensitive entity + Handle(SelectMgr_SelectableObject) mySelectableObject; //!< the current presentation +}; + +#endif diff --git a/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.cxx b/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.cxx index 1f15cf506a..bd590e5c41 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.cxx +++ b/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.cxx @@ -15,7 +15,10 @@ #include +#include +#include #include +#include #include #include @@ -50,7 +53,8 @@ int VInspector_ItemSelectMgrViewerSelector::initRowCount() const if (Column() != 0) return 0; - Standard_Integer aNbRows = GetFirstChildOfPicked(); // SelectMgr_SelectingVolumeManager + // SelectMgr_SelectingVolumeManager, VInspector_ItemSelectMgrSelectableObjectSet, VInspector_ItemContainer + Standard_Integer aNbRows = GetFirstChildOfPicked(); Handle(SelectMgr_ViewerSelector) aViewSelector = GetViewerSelector(); if (!aViewSelector.IsNull()) @@ -125,6 +129,80 @@ void VInspector_ItemSelectMgrViewerSelector::Reset() setViewerSelector (NULL); } +// ======================================================================= +// function : GetSensitiveEntitySet +// purpose : +// ======================================================================= +Handle(SelectMgr_SensitiveEntitySet) VInspector_ItemSelectMgrViewerSelector::GetSensitiveEntitySet (const int theRow, + Handle(SelectMgr_SelectableObject)& theObject) +{ + Standard_Integer anIndex = 0; + + Handle(SelectMgr_ViewerSelector) aViewSelector = GetViewerSelector(); + if (aViewSelector.IsNull()) + return NULL; + + for (SelectMgr_MapOfObjectSensitivesIterator anIterator (aViewSelector->GetObjectSensitives()); anIterator.More(); anIterator.Next(), anIndex++) + { + if (anIndex != theRow) + continue; + + theObject = anIterator.Key(); + return anIterator.Value(); + } + return NULL; +} + +// ======================================================================= +// function : GetContainerRowCount +// purpose : +// ======================================================================= + +int VInspector_ItemSelectMgrViewerSelector::GetContainerRowCount (const int theContainerRow) const +{ + if (theContainerRow != 2) + return 0; + + Handle(SelectMgr_ViewerSelector) aViewSelector = GetViewerSelector(); + if (aViewSelector.IsNull()) + return 0; + + return aViewSelector->GetObjectSensitives().Extent(); +} + +// ======================================================================= +// function : GetContainerValue +// purpose : +// ======================================================================= + +QVariant VInspector_ItemSelectMgrViewerSelector::GetContainerValue (const int theContainerRow, const int theItemRole) const +{ + if (theContainerRow != 2) + return 0; + + if (theItemRole != Qt::DisplayRole) + return QVariant(); + + Handle(SelectMgr_ViewerSelector) aViewSelector = GetViewerSelector(); + if (aViewSelector.IsNull()) + return QVariant(); + + return "SelectMgr_MapOfObjectSensitives"; +} + +// ======================================================================= +// function : CreateContainerChild +// purpose : +// ======================================================================= + +TreeModel_ItemBasePtr VInspector_ItemSelectMgrViewerSelector::CreateContainerChild (const TreeModel_ItemBasePtr& theParent, const int theContainerRow, int theRow, int theColumn) +{ + if (theContainerRow != 2) + return TreeModel_ItemBasePtr(); + + return VInspector_ItemSelectMgrSensitiveEntitySet::CreateItem (theParent, theRow, theColumn); +} + // ======================================================================= // function : initItem // purpose : @@ -245,6 +323,20 @@ bool VInspector_ItemSelectMgrViewerSelector::SetTableData (const int theRow, con return Standard_True; } +// ======================================================================= +// function : Dump +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemSelectMgrViewerSelector::Dump (Standard_OStream& OS) const +{ + Handle(SelectMgr_ViewerSelector) aViewerSelector = GetViewerSelector(); + if (aViewerSelector.IsNull()) + return Standard_False; + + aViewerSelector->Dump (OS); + return Standard_True; +} + // ======================================================================= // function : buildPresentationShape // purpose : @@ -272,12 +364,10 @@ TreeModel_ItemBasePtr VInspector_ItemSelectMgrViewerSelector::createChild (int t { if (theRow == 0) return VInspector_ItemSelectMgrSelectingVolumeManager::CreateItem (currentItem(), theRow, theColumn); + else if (theRow == 1) + return VInspector_ItemSelectMgrSelectableObjectSet::CreateItem (currentItem(), theRow, theColumn); + else if (theRow == 2) + return VInspector_ItemContainer::CreateItem (currentItem(), theRow, theColumn); else return VInspector_ItemSelectMgrViewerSelectorPicked::CreateItem (currentItem(), theRow, theColumn); - //else if (theRow == 1) - // return VInspector_ItemAspectWindow::CreateItem (currentItem(), theRow, theColumn); - //else if (theRow == 2) - // return VInspector_ItemGraphic3dCView::CreateItem (currentItem(), theRow, theColumn); - // - return TreeModel_ItemBasePtr(); } diff --git a/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.hxx b/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.hxx index 978a70b34b..1367767873 100644 --- a/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.hxx +++ b/tools/VInspector/VInspector_ItemSelectMgrViewerSelector.hxx @@ -18,9 +18,11 @@ #include #include +#include #include #include +#include class VInspector_ItemSelectMgrViewerSelector; typedef QExplicitlySharedDataPointer VInspector_ItemSelectMgrViewerSelectorPtr; @@ -28,7 +30,7 @@ typedef QExplicitlySharedDataPointer VIn //! \class VInspector_ItemSelectMgrViewerSelector //! Parent item, that corresponds Folder under the AIS_InteractiveContext //! Children of the item are: none -class VInspector_ItemSelectMgrViewerSelector : public VInspector_ItemBase +class VInspector_ItemSelectMgrViewerSelector : public VInspector_ItemBase, public VInspector_ItemContainerAPI { public: @@ -55,7 +57,31 @@ public: //! Returns the span from the 0 row to the first item corresponded to the picked item //! the 0 item is SelectMgr_SelectingVolumeManager - Standard_Integer GetFirstChildOfPicked() const { return 1; } + //! the 1 item is VInspector_ItemSelectMgrSelectableObjectSet + //! the 2 item is VInspector_ItemContainer for SelectMgr_MapOfObjectSensitives + Standard_Integer GetFirstChildOfPicked() const { return 3; } + + //! Returns entity set if possible from SelectMgr_MapOfObjectSensitives + //! \param theRow row index + //! \param theObject [out] object connected to the sensitive entity set + Standard_EXPORT Handle(SelectMgr_SensitiveEntitySet) GetSensitiveEntitySet (const int theRow, + Handle(SelectMgr_SelectableObject)& theObject); + + //! Returns number of item selected + //! \return rows count + virtual int GetContainerRowCount (const int theContainerRow) const Standard_OVERRIDE; + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + virtual QVariant GetContainerValue (const int theContainerRow, const int theItemRole) const Standard_OVERRIDE; + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + virtual TreeModel_ItemBasePtr CreateContainerChild (const TreeModel_ItemBasePtr& theParent, const int theContainerRow, int theRow, int theColumn) Standard_OVERRIDE; + protected: //! Initialize the current item. It is empty because Reset() is also empty. virtual void initItem() const Standard_OVERRIDE; @@ -90,6 +116,9 @@ protected: //! \param theValue a new cell value virtual bool SetTableData (const int theRow, const int theColumn, const QVariant& theValue) Standard_OVERRIDE; + //! Dumps the content of me on the stream . + virtual Standard_Boolean Dump (Standard_OStream& OS) const; + protected: //! Build presentation shape diff --git a/tools/VInspector/VInspector_ItemV3dView.cxx b/tools/VInspector/VInspector_ItemV3dView.cxx index beb64c9555..668ae51786 100644 --- a/tools/VInspector/VInspector_ItemV3dView.cxx +++ b/tools/VInspector/VInspector_ItemV3dView.cxx @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -130,8 +131,13 @@ int VInspector_ItemV3dView::GetTableRowCount() const // function : GetTableEditType // purpose : // ======================================================================= -ViewControl_EditType VInspector_ItemV3dView::GetTableEditType (const int, const int) const +ViewControl_EditType VInspector_ItemV3dView::GetTableEditType (const int theRow, const int) const { + switch (theRow) + { + case 2: return ViewControl_EditType_DoubleVector; + } + return ViewControl_EditType_None; } @@ -217,8 +223,36 @@ QVariant VInspector_ItemV3dView::GetTableData (const int theRow, const int theCo // function : SetTableData // purpose : // ======================================================================= -bool VInspector_ItemV3dView::SetTableData (const int, const int, const QVariant&) +bool VInspector_ItemV3dView::SetTableData (const int theRow, const int theColumn, const QVariant& theValue) { + Handle(V3d_View) aView = GetView(); + if (aView.IsNull()) + return false; + + if (theColumn == 0) + return false; + + switch (theRow) + { + case 2: + { + QString aValue = theValue.toString(); + Standard_Real aX, anY, aZ, aVx, aVy, aVz; + QList aValues = ViewControl_TableDoubleVector::GetListVector(aValue); + + if (aValues.size() == 3) + { + aX = aValues[0].toFloat(); + anY = aValues[1].toFloat(); + aZ = aValues[2].toFloat(); + + Standard_Real aTmpX, aTmpY, aTmpZ; + aView->Axis(aTmpX, aTmpY, aTmpZ, aVx, aVy, aVz); + + aView->SetAxis(aX, anY, aZ, aVx, aVy, aVz); + } + } + } return true; } diff --git a/tools/VInspector/VInspector_PreviewParameters.cxx b/tools/VInspector/VInspector_PreviewParameters.cxx new file mode 100644 index 0000000000..7b3f80cea3 --- /dev/null +++ b/tools/VInspector/VInspector_PreviewParameters.cxx @@ -0,0 +1,120 @@ +// Created on: 2019-05-03 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +VInspector_PreviewParameters::VInspector_PreviewParameters() +{ + myDrawer = new Prs3d_Drawer(); + + Quantity_Color aColor(Quantity_NOC_TOMATO);//Quantity_NOC_GREENYELLOW));//Quantity_NOC_BLUE1)); + Standard_ShortReal aTransparency = 0.8; + + // point parameters + myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0)); + + // shading parameters + Graphic3d_MaterialAspect aShadingMaterial; + aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + + myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); + 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); +} + +// ======================================================================= +// function : SaveState +// purpose : +// ======================================================================= +void VInspector_PreviewParameters::SaveState (VInspector_PreviewParameters* theParameters, + QMap& theItems, + const QString& thePrefix) +{ + Handle(Prs3d_Drawer) aDrawer = theParameters->GetDrawer(); + + //Quantity_Color aColor = aDrawer->Color(); + //Standard_ShortReal aTransparency = aDrawer->Transparency(); + + //// point parameters + //{ + // Standard_Boolean anOwnPointAspect = aDrawer->HasOwnPointAspect(); + // Standard_SStream OS; + // if (anOwnPointAspect) + // myDrawer->PointAspect()->Dump (OS); + // TCollection_AsciiString aStream (OS.str().c_str()); + // theItems[thePrefix + "has_point_aspect"] = anOwnPointAspect; + // theItems[thePrefix + "point_aspect"] = aStream.ToCString(); + //} + //// shading parameters + //{ + // Standard_Boolean anOwnShadingAspect = aDrawer->HasOwnShadingAspect(); + // Standard_SStream OS; + // if (anOwnShadingAspect) + // myDrawer->ShadingAspect()->Dump (OS); + // TCollection_AsciiString aStream (OS.str().c_str()); + // theItems[thePrefix + "has_shading_aspect"] = anOwnShadingAspect; + // theItems[thePrefix + "shading_aspect"] = aStream.ToCString(); + //} +} + +// ======================================================================= +// function : RestoreState +// purpose : +// ======================================================================= +bool VInspector_PreviewParameters::RestoreState (VInspector_PreviewParameters* theParameters, + const QString& theKey, const QString& theValue, + const QString& thePrefix) +{ + //if (theKey == thePrefix + "has_point_aspect") // point parameters + //{ + // myDrawer->SetOwnPointAspect (theValue.toBool()); + //} + //else if (theKey == thePrefix + "point_aspect") // point parameters + //{ + // Standard_SStream aStream; + // aStream << theValue.ToString().ToStdString(); + // myDrawer->PointAspect()->Init (aStream); + //} + //else if (theKey == thePrefix + "has_shading_aspect") // shading parameters + //{ + // myDrawer->SetOwnShadingAspect (theValue.toBool()); + //} + //else if (theKey == thePrefix + "shading_aspect") // shading parameters + //{ + // Standard_SStream aStream; + // aStream << theValue.ToString().ToStdString(); + // myDrawer->ShadingAspect()->Init (aStream); + //} + //else + // return false; + return true; +} diff --git a/tools/VInspector/VInspector_PreviewParameters.hxx b/tools/VInspector/VInspector_PreviewParameters.hxx new file mode 100644 index 0000000000..e98bea6260 --- /dev/null +++ b/tools/VInspector/VInspector_PreviewParameters.hxx @@ -0,0 +1,68 @@ +// Created on: 2019-05-03 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_PreviewParameters_H +#define VInspector_PreviewParameters_H + +#include +#include + +#include + +#include +#include +#include +#include + +//! \class VInspector_PreviewParameters +//! Container of View tool bar actions +class VInspector_PreviewParameters +{ +public: + + //! Constructor + Standard_EXPORT VInspector_PreviewParameters (); + + //! Destructor + virtual ~VInspector_PreviewParameters() {} + + //! Returns main control + const Handle(Prs3d_Drawer)& GetDrawer() const { return myDrawer; } + + //! Save state of three view in a container in form: key, value. It saves: + //! - visibiblity of columns, + //! - columns width + //! \param theTreeView a view instance + //! \param theItems [out] properties + //! \param thePrefix peference item prefix + Standard_EXPORT static void SaveState (VInspector_PreviewParameters* theParameters, + QMap& theItems, + const QString& thePrefix = QString()); + //! Restore state of three view by a container + //! \param theTreeView a view instance + //! \param theKey property key + //! \param theValue property value + //! \param thePrefix peference item prefix + //! \return boolean value whether the property is applyed to the tree view + Standard_EXPORT static bool RestoreState (VInspector_PreviewParameters* theParameters, + const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()); + +private: + + Handle(Prs3d_Drawer) myDrawer; +}; + +#endif diff --git a/tools/VInspector/VInspector_PropertiesCreator.cxx b/tools/VInspector/VInspector_PropertiesCreator.cxx new file mode 100644 index 0000000000..7d376c977e --- /dev/null +++ b/tools/VInspector/VInspector_PropertiesCreator.cxx @@ -0,0 +1,36 @@ +// Created on: 2019-04-28 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include + +#include + +IMPLEMENT_STANDARD_RTTIEXT(VInspector_PropertiesCreator, TreeModel_ItemPropertiesCreator) + +// ======================================================================= +// function : GetProperties +// purpose : +// ======================================================================= +TreeModel_ItemProperties* VInspector_PropertiesCreator::GetProperties (const TreeModel_ItemBasePtr& theItem) +{ + Standard_SStream aSStream; + if (theItem->Dump (aSStream)) + return new ViewControl_PropertiesStream (theItem); + + return NULL; +} + diff --git a/tools/VInspector/VInspector_PropertiesCreator.hxx b/tools/VInspector/VInspector_PropertiesCreator.hxx new file mode 100644 index 0000000000..b0673db741 --- /dev/null +++ b/tools/VInspector/VInspector_PropertiesCreator.hxx @@ -0,0 +1,47 @@ +// Created on: 2019-04-28 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef VInspector_PropertiesCreator_H +#define VInspector_PropertiesCreator_H + +#include +#include + +#include + +DEFINE_STANDARD_HANDLE (VInspector_PropertiesCreator, TreeModel_ItemPropertiesCreator) + +//! \class VInspector_PropertiesCreator +//! \brief An interface to create custom panes by transient object name. +class VInspector_PropertiesCreator : public TreeModel_ItemPropertiesCreator +{ +public: + + //! Constructor + VInspector_PropertiesCreator() {} + + //! Destructor + virtual ~VInspector_PropertiesCreator() {} + + //! Returns pane for the name, creates a new pane if it does not exist and possible to create + //! \param theName type of the pane + //! \return a pane instance or NULL + virtual TreeModel_ItemProperties* GetProperties (const TreeModel_ItemBasePtr& theItem) Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(VInspector_PropertiesCreator, TreeModel_ItemPropertiesCreator) + +}; + +#endif diff --git a/tools/VInspector/VInspector_Tools.cxx b/tools/VInspector/VInspector_Tools.cxx index a44046decd..7f8bbb001c 100644 --- a/tools/VInspector/VInspector_Tools.cxx +++ b/tools/VInspector/VInspector_Tools.cxx @@ -600,6 +600,30 @@ TopoDS_Shape VInspector_Tools::CreateShape (const Bnd_Box& theBoundingBox) return CreateBoxShape (aPntMin, aPntMax); } +//======================================================================= +//function : CreateShape +//purpose : +//======================================================================= +TopoDS_Shape VInspector_Tools::CreateShape (const Bnd_OBB& theBoundingBox) +{ + if (theBoundingBox.IsVoid()) + return TopoDS_Shape(); + + 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)))); + + return aCompound; +} + //======================================================================= //function : CreateShape //purpose : diff --git a/tools/VInspector/VInspector_Tools.hxx b/tools/VInspector/VInspector_Tools.hxx index add7d38fdc..4ca765d517 100644 --- a/tools/VInspector/VInspector_Tools.hxx +++ b/tools/VInspector/VInspector_Tools.hxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -191,7 +192,7 @@ public: //! Creates box shape //! \param theBoundingBox box shape parameters //! \return created shape - Standard_EXPORT static TopoDS_Shape CreateShape (const Select3D_BndBox3d& theBoundingBox); + Standard_EXPORT static TopoDS_Shape CreateShape (const Bnd_OBB& theBoundingBox); //! Creates box shape //! \param thePntMin minimum point on the bounding box @@ -199,6 +200,11 @@ public: //! \return created shape Standard_EXPORT static TopoDS_Shape CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax); + //! Creates box shape + //! \param theBoundingBox box shape parameters + //! \return created shape + Standard_EXPORT static TopoDS_Shape CreateShape (const Select3D_BndBox3d& theBoundingBox); + //! Build string presentation of Graphic3D index buffer //! \param theIndexBuffer index buffer //! \return string presentation diff --git a/tools/VInspector/VInspector_Window.cxx b/tools/VInspector/VInspector_Window.cxx index 8187ac7a17..f1f2e0a86d 100644 --- a/tools/VInspector/VInspector_Window.cxx +++ b/tools/VInspector/VInspector_Window.cxx @@ -19,8 +19,10 @@ #include #include #include +#include +#include +#include #include -#include #include #include @@ -45,6 +47,8 @@ #include #include #include +#include +#include #include #include #include @@ -106,6 +110,8 @@ const int VINSPECTOR_DEFAULT_VIEW_POSITION_Y = 60; // TINSPECTOR_DEFAULT_POSITIO VInspector_Window::VInspector_Window() : myParent (0), myExportToShapeViewDialog (0), myViewWindow (0) { + myPreviewParameters = new VInspector_PreviewParameters(); + myMainWindow = new QMainWindow (0); QWidget* aCentralWidget = new QWidget (myMainWindow); @@ -127,6 +133,7 @@ VInspector_Window::VInspector_Window() //((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (VINSPECTOR_DEFAULT_TREE_VIEW_WIDTH, // VINSPECTOR_DEFAULT_TREE_VIEW_HEIGHT)); VInspector_ViewModel* aTreeModel = new VInspector_ViewModel (myTreeView); + aTreeModel-> AddPropertiesCreator(new VInspector_PropertiesCreator()); myTreeView->setModel (aTreeModel); // hide Visibility column TreeModel_HeaderSection anItem = aTreeModel->GetHeaderItem ((int)TreeModel_ColumnType_Visibility); @@ -247,9 +254,16 @@ void VInspector_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theIte } anItems.clear(); - TreeModel_Tools::SaveState (myHistoryView, anItems, "history_view_"); + VInspector_PreviewParameters::SaveState (myPreviewParameters, anItems, "preview_parameters_"); for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); + + anItems.clear(); + TreeModel_Tools::SaveState (myTreeView, anItems); + for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) + { + theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); + } } // ======================================================================= @@ -274,6 +288,9 @@ void VInspector_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& else if (TreeModel_Tools::RestoreState (myHistoryView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString(), "history_view_")) continue; + else if (VInspector_PreviewParameters::RestoreState (myPreviewParameters, anItemIt.Key().ToCString(), anItemIt.Value().ToCString(), + "preview_parameters_")) + continue; } } @@ -380,7 +397,7 @@ NCollection_List VInspector_Window::GetSelectedShapes (const QMode { TreeModel_ItemBasePtr anItem = *anItemIt; VInspector_ItemBasePtr aVItem = itemDynamicCast(anItem); - if (!aVItem || aVItem->Row() == 0) + if (!aVItem /*|| aVItem->Row() == 0*/) continue; TopoDS_Shape aShape = aVItem->GetPresentationShape(); @@ -535,8 +552,13 @@ Handle(Graphic3d_TransformPers) VInspector_Window::GetSelectedTransformPers() // ======================================================================= bool VInspector_Window::Init (const NCollection_List& theParameters) { + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aViewModel) + return Standard_False; + Handle(AIS_InteractiveContext) aContext; Handle(VInspector_CallBack) aCallBack; + Standard_Boolean isModelUpdated = Standard_False; for (NCollection_List::Iterator aParamsIt (theParameters); aParamsIt.More(); aParamsIt.Next()) { @@ -552,21 +574,20 @@ bool VInspector_Window::Init (const NCollection_List Handle(ViewControl_PaneCreator) aPaneCreator = Handle(ViewControl_PaneCreator)::DownCast (anObject); if (!myPaneCreators.Contains (aPaneCreator)) myPaneCreators.Append (aPaneCreator); + isModelUpdated = Standard_True; } if (!Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject).IsNull()) { - Handle(TreeModel_ItemPropertiesCreator) aPropCreator = Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject); - VInspector_ViewModel* aViewModel = dynamic_cast(myTreeView->model()); - aViewModel->AddPropertiesCreator (aPropCreator); + Handle(TreeModel_ItemPropertiesCreator) aPropCreator = Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject); + VInspector_ViewModel* aViewModel = dynamic_cast(myTreeView->model()); + aViewModel->AddPropertiesCreator (aPropCreator); + isModelUpdated = Standard_True; } } - if (aContext.IsNull()) - return false; - VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); - if (aViewModel && aViewModel->GetContext() == aContext) - UpdateTreeModel(); + if (aViewModel->GetContext() != aContext) + SetContext(aContext); else - SetContext (aContext); + isModelUpdated = Standard_True; if (!aCallBack.IsNull() && aCallBack != myCallBack) { @@ -576,6 +597,10 @@ bool VInspector_Window::Init (const NCollection_List myCallBack->SetContext(aContext); myCallBack->SetHistoryModel(aHistoryModel); } + + if (isModelUpdated) + UpdateTreeModel(); + return true; } @@ -585,12 +610,22 @@ bool VInspector_Window::Init (const NCollection_List // ======================================================================= void VInspector_Window::SetContext (const Handle(AIS_InteractiveContext)& theContext) { + if (theContext.IsNull()) + return; + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + bool isFirst = aViewModel->GetContext().IsNull(); + aViewModel->SetContext (theContext); myTreeView->setExpanded (aViewModel->index (0, 0), true); if (!myCallBack.IsNull()) myCallBack->SetContext (theContext); + + myPreviewParameters->GetDrawer()->Link (theContext->DefaultDrawer()); + + if (isFirst) + onExportToMessageView(); } // ======================================================================= @@ -647,6 +682,20 @@ void VInspector_Window::onTreeViewContextMenuRequested(const QPoint& thePosition { QMenu* aMenu = new QMenu (GetMainWindow()); aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Export to ShapeView"), SLOT (onExportToShapeView()), GetMainWindow(), this)); + aMenu->addSeparator(); + + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (myTreeView->selectionModel()->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (anItemBase) + { + if (itemDynamicCast (anItemBase)) + { + aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Export to MessageView"), SLOT (onExportToMessageView()), GetMainWindow(), this)); + aMenu->addSeparator(); + + aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Default preview"), SLOT (onDefaultPreview()), GetMainWindow(), this)); + } + } aMenu->addSeparator(); for (int aTypeId = (int)VInspector_DisplayActionType_DisplayId; aTypeId <= (int)VInspector_DisplayActionType_RemoveId; aTypeId++) @@ -811,6 +860,29 @@ void VInspector_Window::onHistoryViewSelectionChanged (const QItemSelection& the selectTreeViewItems (aPointers); } +// ======================================================================= +// function : onExportToShapeView +// purpose : +// ======================================================================= +void VInspector_Window::onExportToMessageView() +{ + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aViewModel) + return; + Handle(AIS_InteractiveContext) aContext = aViewModel->GetContext(); + + TCollection_AsciiString aPluginName ("TKMessageView"); + NCollection_List aParameters; + if (myParameters->FindParameters (aPluginName)) + aParameters = myParameters->Parameters (aPluginName); + + QStringList anExportedPointers; + anExportedPointers.append (VInspector_Tools::GetPointerInfo (aContext, true).ToCString()); + aParameters.Append (aContext); + + myParameters->SetParameters (aPluginName, aParameters, false);//myExportToShapeViewDialog->IsAccepted()); +} + // ======================================================================= // function : onExportToShapeView // purpose : @@ -819,8 +891,6 @@ void VInspector_Window::onExportToShapeView() { const QModelIndexList anIndices; NCollection_List aSelectedShapes = GetSelectedShapes (myTreeView->selectionModel()->selectedIndexes()); - if (aSelectedShapes.Extent() <= 0) - return; TCollection_AsciiString aPluginName ("TKShapeView"); NCollection_List aParameters; @@ -832,20 +902,42 @@ void VInspector_Window::onExportToShapeView() anItemNames = myParameters->GetSelectedNames (aPluginName); QStringList anExportedPointers; - for (NCollection_List::Iterator anIOIt (aSelectedShapes); anIOIt.More(); anIOIt.Next()) + if (aSelectedShapes.Extent() > 0) { - const TopoDS_Shape& aShape = anIOIt.Value(); - if (aShape.IsNull()) + for (NCollection_List::Iterator anIOIt (aSelectedShapes); anIOIt.More(); anIOIt.Next()) + { + const TopoDS_Shape& aShape = anIOIt.Value(); + if (aShape.IsNull()) + continue; + aParameters.Append (aShape.TShape()); + anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString(aShape)); + anExportedPointers.append (VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString()); + } + } + + // seach for objects to be exported + QList anItems = TreeModel_ModelBase::GetSelectedItems (myTreeView->selectionModel()->selectedIndexes()); + for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); anItemIt++) + { + TreeModel_ItemBasePtr anItem = *anItemIt; + VInspector_ItemBasePtr aVItem = itemDynamicCast(anItem); + if (!aVItem) + continue; + + Handle(Standard_Transient) anObject = aVItem->GetObject(); + if (anObject.IsNull()) continue; - aParameters.Append (aShape.TShape()); - anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString(aShape)); - anExportedPointers.append (VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString()); + + aParameters.Append (anObject); + anItemNames.Append (anObject->DynamicType()->Name()); + anExportedPointers.append (VInspector_Tools::GetPointerInfo (anObject, true).ToCString()); } - if (anExportedPointers.empty()) + + if (anExportedPointers.isEmpty()) return; TCollection_AsciiString aPluginShortName = aPluginName.SubString (3, aPluginName.Length()); - QString aMessage = QString ("TShape %1 is sent to %2.") + QString aMessage = QString ("Objects %1 are sent to %2.") .arg (anExportedPointers.join(", ")) .arg (aPluginShortName.ToCString()); QString aQuestion = QString ("Would you like to activate %1 immediately?\n") @@ -860,6 +952,36 @@ void VInspector_Window::onExportToShapeView() myParameters->SetParameters (aPluginName, aParameters, myExportToShapeViewDialog->IsAccepted()); } +// ======================================================================= +// function : onDefaultPreview +// purpose : +// ======================================================================= +void VInspector_Window::onDefaultPreview() +{ + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aViewModel) + return; + + Handle(AIS_InteractiveContext) aContext = aViewModel->GetContext(); + if (aContext.IsNull()) + return; + + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeVertex (gp_Pnt(25., 10., 0.))); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt(20., 20., 0.), gp_Pnt(30., 20., 10.))); + //aBuilder.Add (aCompound, BRepBuilderAPI_MakeFace (gp_Pln (gp_Pnt (20., 30., 0.), gp_Dir (1., 0., 0.))).Face()); + aBuilder.Add (aCompound, VInspector_Tools::CreateBoxShape (gp_Pnt(20., 40., 0.), gp_Pnt(30., 60., 10.))); + + Handle(AIS_Shape) aDefaultPreview = new AIS_Shape (aCompound); + aDefaultPreview->SetAttributes (myPreviewParameters->GetDrawer()); + if (!aContext.IsNull()) + aContext->Display (aDefaultPreview, AIS_Shaded, -1/*do not participate in selection*/, Standard_True); + + UpdateTreeModel(); +} + // ======================================================================= // function : onDisplayActionTypeClicked // purpose : @@ -1128,7 +1250,7 @@ Handle(AIS_InteractiveContext) VInspector_Window::createView() aTrihedron->SetDatumDisplayMode (Prs3d_DM_Shaded); aContext->Display (aTrihedron, Standard_True); - myViewWindow = new View_Window (0, aContext); + myViewWindow = new View_Window (0, aContext, false /*for opening several BREP files*/, true); myViewWindow->GetView()->SetPredefinedSize (VINSPECTOR_DEFAULT_VIEW_WIDTH, VINSPECTOR_DEFAULT_VIEW_HEIGHT); myViewWindow->move (VINSPECTOR_DEFAULT_VIEW_POSITION_X, VINSPECTOR_DEFAULT_VIEW_POSITION_Y); myViewWindow->show(); @@ -1186,12 +1308,8 @@ void VInspector_Window::updatePreviewPresentation (const NCollection_ListAttributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0)); - myPreviewPresentation->SetColor (aColor); - myPreviewPresentation->SetZLayer (Graphic3d_ZLayerId_Topmost); + myPreviewPresentation->SetAttributes (myPreviewParameters->GetDrawer()); myPreviewPresentation->SetTransformPersistence(thePersistent); if (!aContext.IsNull()) @@ -1229,10 +1347,9 @@ void VInspector_Window::updatePreviewPresentation (const NCollection_ListSetAttributes (myPreviewParameters->GetDrawer()); myOpenGlPreviewPresentation->Set (theElements); - myOpenGlPreviewPresentation->SetColor (Quantity_Color (Quantity_NOC_BLUE1)); - myOpenGlPreviewPresentation->SetZLayer (Graphic3d_ZLayerId_Topmost); myOpenGlPreviewPresentation->SetTransformPersistence(thePersistent); if (!aContext.IsNull()) aContext->Display (myOpenGlPreviewPresentation, Standard_True); diff --git a/tools/VInspector/VInspector_Window.hxx b/tools/VInspector/VInspector_Window.hxx index b806e92518..0c774f8bb0 100644 --- a/tools/VInspector/VInspector_Window.hxx +++ b/tools/VInspector/VInspector_Window.hxx @@ -35,12 +35,14 @@ class OpenGl_Element; -class VInspector_PrsOpenGlElement; +class VInspector_PreviewParameters; class ViewControl_MessageDialog; class ViewControl_PropertyView; +class VInspector_PrsOpenGlElement; class VInspector_ToolBar; + class View_Window; class QAbstractItemModel; @@ -164,9 +166,15 @@ private slots: //! \param theDeselected a deselected items void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + //! Exports the selected context into MessageView for have preview in the context. + void onExportToMessageView(); + //! Exports the first selected shape into ShapeViewer plugin. void onExportToShapeView(); + //! Displays default preview presentation + void onDefaultPreview(); + //! Apply activated display action void onDisplayActionTypeClicked(); @@ -259,6 +267,7 @@ private: View_Window* myViewWindow; //!< temporary view window, it is created if Open is called but context is still NULL Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container + VInspector_PreviewParameters* myPreviewParameters; //!< drawer of preview presentation Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object Handle(VInspector_PrsOpenGlElement) myOpenGlPreviewPresentation; //!< presentation of preview for OpenGl elements diff --git a/tools/VInspectorPaneAIS/VInspectorPaneAIS_PropertiesCreator.hxx b/tools/VInspectorPaneAIS/VInspectorPaneAIS_PropertiesCreator.hxx index a4f8e6e13e..76115eb042 100644 --- a/tools/VInspectorPaneAIS/VInspectorPaneAIS_PropertiesCreator.hxx +++ b/tools/VInspectorPaneAIS/VInspectorPaneAIS_PropertiesCreator.hxx @@ -20,10 +20,6 @@ #include #include -#include - -#include -#include DEFINE_STANDARD_HANDLE (VInspectorPaneAIS_PropertiesCreator, TreeModel_ItemPropertiesCreator) @@ -46,8 +42,6 @@ public: DEFINE_STANDARD_RTTIEXT(VInspectorPaneAIS_PropertiesCreator, TreeModel_ItemPropertiesCreator) -private: - NCollection_DataMap myPanes; //!< created panes }; #endif diff --git a/tools/View/View_Displayer.cxx b/tools/View/View_Displayer.cxx index 49fa790828..a74d190df1 100644 --- a/tools/View/View_Displayer.cxx +++ b/tools/View/View_Displayer.cxx @@ -313,7 +313,7 @@ Handle(Standard_Transient) View_Displayer::CreatePresentation (const TopoDS_Shap { Handle(AIS_Shape) aShape = new AIS_Shape (theShape); - aShape->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0)); + //aShape->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0)); return aShape; } diff --git a/tools/View/View_Viewer.cxx b/tools/View/View_Viewer.cxx index ef24ca5231..04907e1479 100644 --- a/tools/View/View_Viewer.cxx +++ b/tools/View/View_Viewer.cxx @@ -19,6 +19,13 @@ #include #include +//#define USE_CLIPPLANE + +#ifdef USE_CLIPPLANE +#include +#include +#endif + // ======================================================================= // function : CreateView // purpose : @@ -26,7 +33,15 @@ void View_Viewer::CreateView() { if (myView.IsNull()) + { myView = myContext->CurrentViewer()->CreateView(); + +#ifdef USE_CLIPPLANE + gp_Pln aPln (gp_Pnt (50, 0, 0), gp_Dir (-1., 0., 0.)); + Handle(Graphic3d_ClipPlane) aClipPlane = new Graphic3d_ClipPlane(aPln); + myView->AddClipPlane (aClipPlane); +#endif + } } // ======================================================================= diff --git a/tools/ViewControl/FILES b/tools/ViewControl/FILES index 7ccc28b096..8c21c99ce9 100644 --- a/tools/ViewControl/FILES +++ b/tools/ViewControl/FILES @@ -8,10 +8,14 @@ ViewControl_Pane.hxx ViewControl_PaneCreator.cxx ViewControl_PaneCreator.hxx ViewControl_PaneItem.hxx +ViewControl_PropertiesStream.cxx +ViewControl_PropertiesStream.hxx ViewControl_PropertyView.cxx ViewControl_PropertyView.hxx ViewControl_Table.cxx ViewControl_Table.hxx +ViewControl_TableDoubleVector.cxx +ViewControl_TableDoubleVector.hxx ViewControl_TableItemDelegate.cxx ViewControl_TableItemDelegate.hxx ViewControl_TableModel.cxx diff --git a/tools/ViewControl/ViewControl_EditType.hxx b/tools/ViewControl/ViewControl_EditType.hxx index 2a095c378a..92fba8084e 100644 --- a/tools/ViewControl/ViewControl_EditType.hxx +++ b/tools/ViewControl/ViewControl_EditType.hxx @@ -26,7 +26,7 @@ enum ViewControl_EditType ViewControl_EditType_Double, //!< line edit widget used double validator ViewControl_EditType_Line, //!< line edit widget ViewControl_EditType_Spin, //!< spin box widget - ViewControl_EditType_DoubleVec3, //!< control to enter three double values + ViewControl_EditType_DoubleVector, //!< control to enter three double values ViewControl_EditType_DoAction //!< control to perform the row action }; diff --git a/tools/ViewControl/ViewControl_PropertiesStream.cxx b/tools/ViewControl/ViewControl_PropertiesStream.cxx new file mode 100644 index 0000000000..fd5ac5a3f0 --- /dev/null +++ b/tools/ViewControl/ViewControl_PropertiesStream.cxx @@ -0,0 +1,115 @@ +// Created on: 2019-04-28 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include + +#include + +#include + +IMPLEMENT_STANDARD_RTTIEXT(ViewControl_PropertiesStream, TreeModel_ItemProperties) + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= + +void ViewControl_PropertiesStream::Init() +{ + if (!getItem() || !myValues.IsEmpty()) + return; + + Standard_SStream aSStream; + getItem()->Dump (aSStream); + + Message::ConvertStream (aSStream, myColumnCount, myValues); +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= + +void ViewControl_PropertiesStream::Reset() +{ + if (!getItem()) + return; + myValues.Clear(); + myColumnCount = 0; +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= + +void ViewControl_PropertiesStream::initItem() const +{ + const_cast(this)->Init(); +} + +// ======================================================================= +// function : GetTableRowCount +// purpose : +// ======================================================================= + +int ViewControl_PropertiesStream::GetTableRowCount() const +{ + initItem(); + + return getValues().Length() / myColumnCount; +} + +// ======================================================================= +// function : GetTableData +// purpose : +// ======================================================================= + +QVariant ViewControl_PropertiesStream::GetTableData (const int theRow, const int theColumn, int theRole) const +{ + if (theRole != Qt::DisplayRole) + return QVariant(); + + initItem(); + + int anIndex = theRow * myColumnCount + theColumn; + if (theRole == Qt::DisplayRole && anIndex < getValues().Length()) + return getValues().Value(anIndex).ToCString(); + + return QVariant(); +} + +// ======================================================================= +// function : GetPresentations +// purpose : +// ======================================================================= + +void ViewControl_PropertiesStream::GetPresentations (const int theRow, + const int theColumn, + NCollection_List& thePresentations) +{ + if (theColumn == 0) + return; + + QVariant aValue = GetTableData (theRow, theColumn, Qt::DisplayRole); + TCollection_AsciiString aStrValue = aValue.toString().toStdString().c_str(); + + gp_XYZ aPoint; + if (!aPoint.FromString (aStrValue)) + return; + + thePresentations.Append (new ViewControl_TransientShape (BRepBuilderAPI_MakeVertex (aPoint))); +} diff --git a/tools/ViewControl/ViewControl_PropertiesStream.hxx b/tools/ViewControl/ViewControl_PropertiesStream.hxx new file mode 100644 index 0000000000..c1317d4190 --- /dev/null +++ b/tools/ViewControl/ViewControl_PropertiesStream.hxx @@ -0,0 +1,91 @@ +// Created on: 2019-04-28 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef ViewControl_PropertiesStream_H +#define ViewControl_PropertiesStream_H + +#include +#include +#include +#include + +#include +#include + +DEFINE_STANDARD_HANDLE (ViewControl_PropertiesStream, TreeModel_ItemProperties) + +//! \class ViewControl_PropertiesStream +//! \brief This is an interace for ViewControl_TableModel to give real values of the model +//! It should be filled or redefined. +class ViewControl_PropertiesStream : public TreeModel_ItemProperties +{ +public: + + //! Constructor + Standard_EXPORT ViewControl_PropertiesStream (const TreeModel_ItemBasePtr& theItem) + : TreeModel_ItemProperties (theItem) {} + + //! Destructor + virtual ~ViewControl_PropertiesStream() {} + + //! If me has internal values, it should be initialized here. + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! If the item has internal values, there should be reseted here. + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns number of table columns + //! \return an integer value + virtual int GetTableColumnCount() const { initItem(); return myColumnCount; } + + //! Returns number of rows, depending on orientation: myColumnCount or size of values container + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int GetTableRowCount() const Standard_OVERRIDE; + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant GetTableData (const int theRow, const int theColumn, const int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! Returns presentation of the attribute to be visualized in the view + //! \param theRow a model index row + //! \param theColumn a model index column + //! \thePresentations [out] container of presentation handles to be visualized + Standard_EXPORT virtual void GetPresentations (const int theRow, const int theColumn, + NCollection_List& thePresentations) Standard_OVERRIDE; + +protected: + //! Returns values + //! @return values + const NCollection_Vector& getValues() const { return myValues; } + +protected: + + //! Initialize me. + Standard_EXPORT void initItem() const; + +public: + DEFINE_STANDARD_RTTIEXT (ViewControl_PropertiesStream, TreeModel_ItemProperties) + +protected: + NCollection_Vector myValues; //!< container of values + Standard_Integer myColumnCount; //!< value to present container of values into table +}; + +#endif diff --git a/tools/ViewControl/ViewControl_TableDoubleVector.cxx b/tools/ViewControl/ViewControl_TableDoubleVector.cxx new file mode 100644 index 0000000000..31cb0aea71 --- /dev/null +++ b/tools/ViewControl/ViewControl_TableDoubleVector.cxx @@ -0,0 +1,264 @@ +//----------------------------------------------------------------------------- +// Created on: 2019-03-28 +// Created by: Vadim LEONTIEV +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of commercial software by OPEN CASCADE SAS. +// +// This software is furnished in accordance with the terms and conditions +// of the contract and with the inclusion of this copyright notice. +// This software or any other copy thereof may not be provided or otherwise +// be made available to any third party. +// No ownership title to the software is transferred hereby. +// +// OPEN CASCADE SAS makes no representation or warranties with respect to the +// performance of this software, and specifically disclaims any responsibility +// for any damages, special or consequential, connected with its use. +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +//! Model for a table of parameters: Values: X, Y, Z +class ViewControl_ParametersModelVector : public ViewControl_TableModelValues +{ +public: + ViewControl_ParametersModelVector(ViewControl_TableDoubleVector* theDoubleVector) + : ViewControl_TableModelValues(), myDoubleVector(theDoubleVector) {} + + virtual ~ViewControl_ParametersModelVector() {} + + //! Inits model by the parameters vector + //! \param theVector model the vector + void SetVector(const QList& theVector) + { + if (myVector.isEmpty()) + { myVector.clear(); } + + for (int aNumberVector = 0; aNumberVector < theVector.size(); ++aNumberVector) + { + myVector.append(theVector[aNumberVector]); + } + } + + //! Returns current vector + //! \return vector value to string + QList GetVector() const { return myVector; } + + //! Returns current vector + //! \return vector value to QList + QList GetListFromString(const QString& theVector) const + { + QList aDoubleList; + + QStringList aList = theVector.split(QString(","), QString::SkipEmptyParts); + if (aList.isEmpty()) + return aDoubleList; + + for (int aNumberValue = 0; aNumberValue < aList.size(); ++aNumberValue) + { + aDoubleList.append(QVariant(aList[aNumberValue])); + } + + return aDoubleList; + } + + //! Returns item information(short) for display role. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant Data(const int theRow, const int theColumn, + int theRole = Qt::DisplayRole) const Standard_OVERRIDE + { + if (theRole != Qt::DisplayRole) + return QVariant(); + + bool isFirstColumn = theColumn == 0; + switch (theRow) + { + case 0: return isFirstColumn ? QVariant("X") : myVector[theRow]; + case 1: return isFirstColumn ? QVariant("Y") : myVector[theRow]; + case 2: return isFirstColumn ? QVariant("Z") : myVector[theRow]; + } + return QVariant(); + } + + //! Sets content of the model index for the given role, it is applyed to internal container of values + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return true if the value is changed + virtual bool SetData(const int theRow, const int theColumn, const QVariant& theValue, int) + { + if (theColumn != 1 || theRow < 0 || theRow > 2) + return false; + + switch (theRow) + { + case 0: myVector[theRow] = theValue; break; + case 1: myVector[theRow] = theValue; break; + case 2: myVector[theRow] = theValue; break; + } + + return true; + } + + //! Returns number of tree level line items = colums in table view + virtual int ColumnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 2; } + + //! Returns onlly one row in table view + virtual int RowCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 3; } + + //! Returns editable flag for DoubleVector + //! \return flags + Qt::ItemFlags Flags(const QModelIndex& theIndex) const + { + Qt::ItemFlags aFlags = ViewControl_TableModelValues::Flags(theIndex); + + if (theIndex.column() == 1 && theIndex.row() >= 0 && theIndex.row() <= 2) + aFlags = aFlags | Qt::ItemIsEditable; + + return aFlags; + } + + //! Returns type of edit control for the model index. By default, it is an empty control + //! \param theRow a model index row + //! \param theColumn a model index column + //! \return edit type + virtual ViewControl_EditType GetEditType(const int theRow, const int theColumn) const + { + if (theColumn == 1 && theRow >= 0 && theRow <= 2) + return ViewControl_EditType_Double; + + return ViewControl_EditType_None; + } + +private: + QList myVector; + ViewControl_TableDoubleVector* myDoubleVector; +}; + + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= + +ViewControl_TableDoubleVector::ViewControl_TableDoubleVector(QWidget* theParent) +: QDialog(theParent) +{ + QGridLayout* aLayout = new QGridLayout(this); + aLayout->setContentsMargins(0, 0, 0, 0); + + myParameters = new QTableView(this); + + ViewControl_TableModel* aTableModel = new ViewControl_TableModel(myParameters); + aTableModel->SetModelValues(new ViewControl_ParametersModelVector(this)); + myParameters->setModel(aTableModel); + + ViewControl_TableItemDelegate* anItemDelegate = new ViewControl_TableItemDelegate(); + anItemDelegate->SetModelValues(aTableModel->GetModelValues()); + myParameters->setItemDelegate(anItemDelegate); + + myParameters->verticalHeader()->setDefaultSectionSize(myParameters->verticalHeader()->minimumSectionSize()); + myParameters->verticalHeader()->setVisible(false); + myParameters->horizontalHeader()->setVisible(false); + myParameters->setMinimumHeight(myParameters->verticalHeader()->minimumSectionSize() * aTableModel->rowCount() + + TreeModel_Tools::HeaderSectionMargin()); + myParameters->setMinimumWidth(myParameters->horizontalHeader()->defaultSectionSize() * aTableModel->columnCount() + + TreeModel_Tools::HeaderSectionMargin()); + + QItemSelectionModel* aSelectionModel = new QItemSelectionModel(myParameters->model()); + myParameters->setSelectionMode(QAbstractItemView::SingleSelection); + myParameters->setSelectionModel(aSelectionModel); + + aLayout->addWidget(myParameters, 0, 0); + + myDialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + connect(myDialogButtons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(myDialogButtons, &QDialogButtonBox::rejected, this, &QDialog::reject); + + aLayout->addWidget(myDialogButtons, 1, 0, 1, 2); +} + +// ======================================================================= +// function : SetVectorValue +// purpose : +// ======================================================================= + +void ViewControl_TableDoubleVector::SetVectorValue(const QString& theVector) +{ + QList aVector = GetListVector(theVector); + // parameters model + ViewControl_TableModel* aTableModel = dynamic_cast (myParameters->model()); + ViewControl_ParametersModelVector* aParametersModel = dynamic_cast (aTableModel->GetModelValues()); + aParametersModel->SetVector(aVector); +} + +// ======================================================================= +// function : GetListVector +// purpose : +// ======================================================================= + +QList ViewControl_TableDoubleVector::GetListVector(const QString& theVector) +{ + QList aDoubleList; + + QStringList aList = theVector.split(ViewControl_TableDoubleVector::DoubleSeparator(), QString::SkipEmptyParts); + + if (aList.isEmpty()) + return aDoubleList; + + for (int aNumberValue = 0; aNumberValue < aList.size(); ++aNumberValue) + { + aDoubleList.append(QVariant(aList[aNumberValue])); + } + + return aDoubleList; +} + +// ======================================================================= +// function : GetVector +// purpose : +// ======================================================================= + +QString ViewControl_TableDoubleVector::GetVector() const +{ + ViewControl_TableModel* aTableModel = dynamic_cast (myParameters->model()); + ViewControl_ParametersModelVector* aParametersModel = dynamic_cast (aTableModel->GetModelValues()); + + return VectorToString(aParametersModel->GetVector()); +} + +// ======================================================================= +// function : VectorToString +// purpose : +// ======================================================================= + +QString ViewControl_TableDoubleVector::VectorToString(const QList& theVector) const +{ + QString aVectorToString; + + for (int aNumberValue = 0; aNumberValue < theVector.size(); ++aNumberValue) + { + aVectorToString += theVector[aNumberValue].toString() + DoubleSeparator(); + } + aVectorToString.remove(aVectorToString.length() - 1, 1); + + return aVectorToString; +} + diff --git a/tools/ViewControl/ViewControl_TableDoubleVector.hxx b/tools/ViewControl/ViewControl_TableDoubleVector.hxx new file mode 100644 index 0000000000..06cad5806d --- /dev/null +++ b/tools/ViewControl/ViewControl_TableDoubleVector.hxx @@ -0,0 +1,76 @@ +//----------------------------------------------------------------------------- +// Created on: 2019-03-28 +// Created by: Vadim LEONTIEV +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of commercial software by OPEN CASCADE SAS. +// +// This software is furnished in accordance with the terms and conditions +// of the contract and with the inclusion of this copyright notice. +// This software or any other copy thereof may not be provided or otherwise +// be made available to any third party. +// No ownership title to the software is transferred hereby. +// +// OPEN CASCADE SAS makes no representation or warranties with respect to the +// performance of this software, and specifically disclaims any responsibility +// for any damages, special or consequential, connected with its use. +//----------------------------------------------------------------------------- + +#ifndef ViewControl_TableDoubleVector_H +#define ViewControl_TableDoubleVector_H + +#include +#include + +#include +#include +#include +#include +#include +#include + +class QDialogButtonBox; +class QTableView; + +//! \class ViewControl_PointCoordinates +//! \dialog of change the point coordinates +class VIEWCONTROL_EXPORT ViewControl_TableDoubleVector : public QDialog +{ + Q_OBJECT +public: + + //! Constructor + ViewControl_TableDoubleVector(QWidget* theParent); + + //! Destructor + virtual ~ViewControl_TableDoubleVector() Standard_OVERRIDE{} + + //! Inits control by the vector value + //! \param theVector text vector value + void SetVectorValue(const QString& theVector); + + //! Returns vector value + //! \return QList vector value + static QList ViewControl_TableDoubleVector::GetListVector(const QString& theVector); + + //! Returns vector value + //! \return text vector value + QString GetVector() const; + + //! Converts vector to string value in form + //! \param theVector vector value + //! \return text value + QString VectorToString(const QList& theVector) const; + +private: + //! Returns symbol used as a separtor of vector components in string conversion + //! \return symbol value + static QString DoubleSeparator() { return ","; } + +private: + QTableView* myParameters; //! current vector parameters + QDialogButtonBox* myDialogButtons; //! OK/Cancel buttons + +}; + +#endif // ViewControl_TableDoubleVector_H diff --git a/tools/ViewControl/ViewControl_TableItemDelegate.cxx b/tools/ViewControl/ViewControl_TableItemDelegate.cxx index 5696212d9d..73f5e939a2 100644 --- a/tools/ViewControl/ViewControl_TableItemDelegate.cxx +++ b/tools/ViewControl/ViewControl_TableItemDelegate.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,7 @@ QWidget* ViewControl_TableItemDelegate::createEditorControl (QWidget* theParent, return aSpinBox; } case ViewControl_EditType_DoAction: return new QPushButton (theParent); + case ViewControl_EditType_DoubleVector: return new ViewControl_TableDoubleVector(theParent); default: return 0; } @@ -185,6 +187,7 @@ void ViewControl_TableItemDelegate::setEditorValue (QWidget* theEditor, const Vi case ViewControl_EditType_Line: (qobject_cast(theEditor))->setText (theValue.toString()); break; case ViewControl_EditType_Spin: (qobject_cast(theEditor))->setValue (theValue.toInt()); break; case ViewControl_EditType_DoAction: (qobject_cast(theEditor))->setText ("UnSelect"); break; + case ViewControl_EditType_DoubleVector: (qobject_cast(theEditor))->SetVectorValue(theValue.toString()); break; default: break; } @@ -207,6 +210,7 @@ QVariant ViewControl_TableItemDelegate::getEditorValue (QWidget* theEditor, cons case ViewControl_EditType_Line: return (qobject_cast(theEditor))->text(); case ViewControl_EditType_Spin: return (qobject_cast(theEditor))->value(); case ViewControl_EditType_DoAction: return QVariant ("Clicked"); + case ViewControl_EditType_DoubleVector: return (qobject_cast(theEditor))->GetVector(); default: return QVariant(); } diff --git a/tools/ViewControl/ViewControl_Tools.cxx b/tools/ViewControl/ViewControl_Tools.cxx index 1bcf999a37..273f805a5c 100644 --- a/tools/ViewControl/ViewControl_Tools.cxx +++ b/tools/ViewControl/ViewControl_Tools.cxx @@ -18,6 +18,13 @@ #include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -260,3 +267,105 @@ TCollection_AsciiString ViewControl_Tools::ToString (const TopLoc_Location& theL { return ToString (theLocation.Transformation()); } + +//======================================================================= +//function : CreateShape +//purpose : +//======================================================================= +TopoDS_Shape ViewControl_Tools::CreateShape (const Bnd_Box& theBoundingBox) +{ + if (theBoundingBox.IsVoid() || theBoundingBox.IsWhole()) + return TopoDS_Shape(); + + 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); +} + +//======================================================================= +//function : CreateShape +//purpose : +//======================================================================= +TopoDS_Shape ViewControl_Tools::CreateShape (const Bnd_OBB& theBoundingBox) +{ + if (theBoundingBox.IsVoid()) + return TopoDS_Shape(); + + 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)))); + + return aCompound; +} + +//======================================================================= +//function : CreateBoxShape +//purpose : +//======================================================================= +TopoDS_Shape ViewControl_Tools::CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax) +{ + Standard_Boolean aThinOnX = fabs (thePntMin.X() - thePntMax.X()) < Precision::Confusion(); + Standard_Boolean aThinOnY = fabs (thePntMin.Y() - thePntMax.Y()) < Precision::Confusion(); + Standard_Boolean aThinOnZ = fabs (thePntMin.Z() - thePntMax.Z()) < Precision::Confusion(); + + if (((int)aThinOnX + (int)aThinOnY + (int)aThinOnZ) > 1) // thin box in several directions is a point + { + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeVertex (thePntMin)); + return aCompound; + } + + if (aThinOnX || aThinOnY || aThinOnZ) + { + gp_Pnt aPnt1, aPnt2, aPnt3, aPnt4 ; + if (aThinOnX) + { + aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z()); + aPnt2 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMin.Z()); + aPnt3 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMax.Z()); + aPnt4 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMax.Z()); + } + else if (aThinOnY) + { + aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z()); + aPnt2 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMin.Z()); + aPnt3 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMax.Z()); + aPnt4 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMax.Z()); + } + else if (aThinOnZ) + { + aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z()); + aPnt2 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMin.Z()); + aPnt3 = gp_Pnt(thePntMax.X(), thePntMax.Y(), thePntMin.Z()); + aPnt4 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMin.Z()); + } + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt1, aPnt2)); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt2, aPnt3)); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt3, aPnt4)); + aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt4, aPnt1)); + + return aCompound; + } + else + { + BRepPrimAPI_MakeBox aBoxBuilder (thePntMin, thePntMax); + return aBoxBuilder.Shape(); + } +} diff --git a/tools/ViewControl/ViewControl_Tools.hxx b/tools/ViewControl/ViewControl_Tools.hxx index 7a9b90a3a4..a701d4df0a 100644 --- a/tools/ViewControl/ViewControl_Tools.hxx +++ b/tools/ViewControl/ViewControl_Tools.hxx @@ -21,11 +21,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -143,6 +145,22 @@ public: //! \return text value Standard_EXPORT static TCollection_AsciiString ToString (const TopLoc_Location& theLocation); + //! Creates box shape + //! \param theBoundingBox box shape parameters + //! \return created shape + Standard_EXPORT static TopoDS_Shape CreateShape (const Bnd_Box& theBoundingBox); + + //! Creates box shape + //! \param theBoundingBox box shape parameters + //! \return created shape + Standard_EXPORT static TopoDS_Shape CreateShape (const Bnd_OBB& theBoundingBox); + + //! 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 TopoDS_Shape CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax); + }; #endif