From 2e08eac5a39c627a87dbe3b23df51c8178a6ad5f Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 25 Feb 2019 11:19:56 +0300 Subject: [PATCH] 0029451: Information Message Alert to debug an algorithm or object functionality Modifications: - Message_AlertExtended to store additional parameters (attributes, composite alert container, performance meter) - Message_Attribute and inherited classes to store custom information about alert - Message_CompositeAlerts to have hierarchical structure of alerts - Message_PerfMeter to automatically calculate time between alerts adding into report - Message_ReportCall back to be able to react to message report filling. - Import/Export message report report. Currently it is implemented using XmlDrivers_MessageReportStorage - MessageView/MessageModel - Inspector plugin for GUI presentation of Message_Report Sample of using alerts: - BRepMesh_IncremetalMesh - till IMeshTools_ShapeExplorer::Accept() for model maps filling (debug of 0030497 issue) DRAW case: - tools/messageview/A1 (cherry picked from commit 9dae9d43ba992a094fb387648bcd5503b487f698) --- src/Draw/Draw.cxx | 23 ++ src/Draw/Draw.hxx | 7 + src/Draw/Draw_Commands.cxx | 1 + src/Draw/Draw_MessageCommands.cxx | 104 ++++++++ src/Draw/Draw_Report.cxx | 50 ++++ src/Draw/Draw_Report.hxx | 69 ++++++ src/Draw/FILES | 3 + src/Message/FILES | 11 +- src/Message/Message.cxx | 36 +++ src/Message/Message.hxx | 17 +- src/Message/Message_Alerts.hxx | 69 ++++++ src/Message/Message_AttributeVectorOfReal.cxx | 68 ------ src/Message/Message_AttributeVectorOfReal.hxx | 58 ----- .../Message_AttributeVectorOfRealVec3.cxx | 69 ------ .../Message_AttributeVectorOfRealVec3.hxx | 56 ----- .../Message_AttributeVectorOfValues.cxx | 118 +++++++++ .../Message_AttributeVectorOfValues.hxx | 68 ++++++ src/Message/Message_Report.cxx | 14 ++ src/Message/Message_Report.hxx | 5 + src/TopoDS/TopoDS_AlertAttribute.hxx | 16 +- .../XmlDrivers_MessageReportStorage.cxx | 67 ++---- tests/tools/grids.list | 1 + tests/tools/messageview/A1 | 12 + tools/MessageModel/FILES | 6 +- tools/MessageModel/MessageModel.qrc | 3 +- tools/MessageModel/MessageModel_Actions.cxx | 23 +- tools/MessageModel/MessageModel_Actions.hxx | 6 +- tools/MessageModel/MessageModel_ItemAlert.cxx | 21 +- tools/MessageModel/MessageModel_ItemAlert.hxx | 2 + .../MessageModel/MessageModel_ItemReport.cxx | 2 + .../MessageModel/MessageModel_ItemReport.hxx | 2 + tools/MessageModel/MessageModel_ItemRoot.cxx | 15 ++ tools/MessageModel/MessageModel_ItemRoot.hxx | 5 + .../MessageModel_TableModelRealValues.cxx | 106 --------- .../MessageModel_TableModelRealVec3Values.cxx | 122 ---------- .../MessageModel_TableModelRealVec3Values.hxx | 67 ------ .../MessageModel_TableModelValues.cxx} | 56 +++-- ....hxx => MessageModel_TableModelValues.hxx} | 31 +-- tools/MessageModel/MessageModel_Tools.cxx | 144 ++++------- tools/MessageModel/MessageModel_Tools.hxx | 10 +- tools/MessageModel/MessageModel_TreeModel.cxx | 13 + tools/MessageModel/MessageModel_TreeModel.hxx | 7 + .../icons/item_vectorOfValues.png | Bin 0 -> 347 bytes .../icons/item_vectorOfValues.svg | 103 ++++++++ .../MessageView_VisibilityState.cxx | 5 +- tools/MessageView/MessageView_Window.cxx | 16 +- tools/TreeModel/FILES | 2 + tools/TreeModel/TreeModel_ItemBase.hxx | 9 + tools/TreeModel/TreeModel_ItemProperties.cxx | 18 ++ tools/TreeModel/TreeModel_ItemProperties.hxx | 86 +++++++ tools/TreeModel/TreeModel_ModelBase.cxx | 12 +- tools/TreeModel/TreeModel_ModelBase.hxx | 11 + tools/TreeModel/TreeModel_Tools.cxx | 50 ++++ tools/TreeModel/TreeModel_Tools.hxx | 19 ++ .../VInspector_TableModelValues.cxx | 30 --- .../VInspector_TableModelValues.hxx | 6 - tools/ViewControl/FILES | 6 +- .../ViewControl/ViewControl_ColorSelector.cxx | 10 +- tools/ViewControl/ViewControl_EditType.hxx | 3 +- .../ViewControl/ViewControl_PropertyView.cxx | 62 ----- .../ViewControl/ViewControl_PropertyView.hxx | 28 --- tools/ViewControl/ViewControl_Table.cxx | 21 +- tools/ViewControl/ViewControl_Table.hxx | 17 +- .../ViewControl_TableItemDelegate.cxx | 23 +- tools/ViewControl/ViewControl_TableModel.cxx | 25 +- tools/ViewControl/ViewControl_TableModel.hxx | 19 +- .../ViewControl_TableModelFilter.hxx | 76 ------ .../ViewControl_TableModelValues.cxx | 44 +++- .../ViewControl_TableModelValues.hxx | 81 +------ .../ViewControl_TableModelValuesDefault.cxx | 48 ++++ .../ViewControl_TableModelValuesDefault.hxx | 92 +++++++ .../ViewControl/ViewControl_TableProperty.cxx | 224 ------------------ .../ViewControl/ViewControl_TableProperty.hxx | 141 ----------- tools/ViewControl/ViewControl_Tools.cxx | 2 +- tools/ViewControl/ViewControl_Tools.hxx | 6 + 75 files changed, 1345 insertions(+), 1533 deletions(-) create mode 100644 src/Draw/Draw_MessageCommands.cxx create mode 100644 src/Draw/Draw_Report.cxx create mode 100644 src/Draw/Draw_Report.hxx create mode 100644 src/Message/Message_Alerts.hxx delete mode 100644 src/Message/Message_AttributeVectorOfReal.cxx delete mode 100644 src/Message/Message_AttributeVectorOfReal.hxx delete mode 100644 src/Message/Message_AttributeVectorOfRealVec3.cxx delete mode 100644 src/Message/Message_AttributeVectorOfRealVec3.hxx create mode 100644 src/Message/Message_AttributeVectorOfValues.cxx create mode 100644 src/Message/Message_AttributeVectorOfValues.hxx create mode 100644 tests/tools/messageview/A1 delete mode 100644 tools/MessageModel/MessageModel_TableModelRealValues.cxx delete mode 100644 tools/MessageModel/MessageModel_TableModelRealVec3Values.cxx delete mode 100644 tools/MessageModel/MessageModel_TableModelRealVec3Values.hxx rename tools/{ViewControl/ViewControl_TableModelFilter.cxx => MessageModel/MessageModel_TableModelValues.cxx} (53%) rename tools/MessageModel/{MessageModel_TableModelRealValues.hxx => MessageModel_TableModelValues.hxx} (59%) create mode 100644 tools/MessageModel/icons/item_vectorOfValues.png create mode 100644 tools/MessageModel/icons/item_vectorOfValues.svg create mode 100644 tools/TreeModel/TreeModel_ItemProperties.cxx create mode 100644 tools/TreeModel/TreeModel_ItemProperties.hxx delete mode 100644 tools/ViewControl/ViewControl_TableModelFilter.hxx create mode 100644 tools/ViewControl/ViewControl_TableModelValuesDefault.cxx create mode 100644 tools/ViewControl/ViewControl_TableModelValuesDefault.hxx delete mode 100644 tools/ViewControl/ViewControl_TableProperty.cxx delete mode 100644 tools/ViewControl/ViewControl_TableProperty.hxx diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index e6292aeb27..cdd6c31b38 100644 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -575,3 +575,26 @@ void Draw::Load(Draw_Interpretor& theDI, const TCollection_AsciiString& theKey, (*fp) (theDI); } +//======================================================================= +//function : ParseOnOff +//purpose : +//======================================================================= +Standard_Boolean Draw::ParseOnOff (Standard_CString theArg, + Standard_Boolean& theIsOn) +{ + TCollection_AsciiString aFlag(theArg); + aFlag.LowerCase(); + if (aFlag == "on" + || aFlag == "1") + { + theIsOn = Standard_True; + return Standard_True; + } + else if (aFlag == "off" + || aFlag == "0") + { + theIsOn = Standard_False; + return Standard_True; + } + return Standard_False; +} diff --git a/src/Draw/Draw.hxx b/src/Draw/Draw.hxx index e546d98902..06005f9c1d 100644 --- a/src/Draw/Draw.hxx +++ b/src/Draw/Draw.hxx @@ -129,6 +129,13 @@ public: //! Defines Draw unit commands Standard_EXPORT static void UnitCommands (Draw_Interpretor& I); + //! Defines Draw message commands + Standard_EXPORT static void MessageCommands (Draw_Interpretor& I); + + //! Parses boolean argument. + //! Handles either flag specified by 0|1 or on|off. + Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString theArg, + Standard_Boolean& theIsOn); diff --git a/src/Draw/Draw_Commands.cxx b/src/Draw/Draw_Commands.cxx index 6444f5d722..32efe9fcd5 100644 --- a/src/Draw/Draw_Commands.cxx +++ b/src/Draw/Draw_Commands.cxx @@ -41,6 +41,7 @@ void Draw::Commands (Draw_Interpretor& theCommands) } Draw::BasicCommands(theCommands); + Draw::MessageCommands(theCommands); Draw::VariableCommands(theCommands); Draw::GraphicCommands(theCommands); Draw::PloadCommands(theCommands); diff --git a/src/Draw/Draw_MessageCommands.cxx b/src/Draw/Draw_MessageCommands.cxx new file mode 100644 index 0000000000..52fb350fa9 --- /dev/null +++ b/src/Draw/Draw_MessageCommands.cxx @@ -0,0 +1,104 @@ +// Created on: 2018-06-10 +// 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 + +//============================================================================== +//function : ActivateReport +//purpose : +//============================================================================== + +static Standard_Integer ActivateReport (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec) +{ + bool isActiveMode = true; + bool isGravityDefined = false; + Standard_Integer aGravity = -1; + for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) + { + const TCollection_AsciiString anArg = theArgVec[anArgIt]; + TCollection_AsciiString anArgCase = anArg; + anArgCase.LowerCase(); + if (anArgCase == "-mode") + { + if (anArgIt + 1 < theArgsNb + && Draw::ParseOnOff (theArgVec[anArgIt + 1], isActiveMode)) + { + ++anArgIt; + } + } + else if (anArgCase == "-gravity") + { + if (anArgIt + 1 < theArgsNb) + { + Message_Gravity aGravityType; + isGravityDefined = Message::GravityFromString (theArgVec[anArgIt + 1], aGravityType); + aGravity = (Standard_Integer)aGravityType; + ++anArgIt; + } + } + else + { + std::cout << "Syntax error: unknown argument " << anArg << ".\n"; + return 1; + } + } + + Handle(Message_Report) aCurrentReport = Message_Report::CurrentReport (isActiveMode); + if (!aCurrentReport.IsNull()) + aCurrentReport->SetActive(isActiveMode, aGravity); + + return 0; +} + +//============================================================================== +//function : ClearReport +//purpose : +//============================================================================== + +static Standard_Integer ClearReport (Draw_Interpretor&, Standard_Integer, const char**) +{ + Handle(Message_Report) aCurrentReport = Message_Report::CurrentReport (Standard_False); + if (!aCurrentReport.IsNull()) + aCurrentReport->Clear(); + + return 0; +} + +//======================================================================= +//function : PloadCommands +//purpose : +//======================================================================= + +void Draw::MessageCommands(Draw_Interpretor& theCommands) +{ + static Standard_Boolean Done = Standard_False; + if (Done) return; + Done = Standard_True; + + const char* g = "DRAW Message Commands"; + + theCommands.Add("activateReport" , + "activateReport [-mode {-on|-off}=-on]" + "[-gravity {trace|info|warning|alarm|fail}]" + "Activates default Message_Report object" , + __FILE__, ActivateReport, g); + + theCommands.Add("clearReport" , "clearReport: Clears content of default Message_Report object" , + __FILE__, ClearReport, g); +} diff --git a/src/Draw/Draw_Report.cxx b/src/Draw/Draw_Report.cxx new file mode 100644 index 0000000000..b3535cc895 --- /dev/null +++ b/src/Draw/Draw_Report.cxx @@ -0,0 +1,50 @@ +// Created on: 2018-06-10 +// 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 + +IMPLEMENT_STANDARD_RTTIEXT(Draw_Report,Draw_Drawable3D) + +//======================================================================= +//function : Copy +//purpose : +//======================================================================= +Handle(Draw_Drawable3D) Draw_Report::Copy()const +{ + Handle(Draw_Report) aReport = new Draw_Report (myReport); + return aReport; +} + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +void Draw_Report::Dump (Standard_OStream& S)const +{ + (void)S; + //S << myReport; +} + + +//======================================================================= +//function : Whatis +//purpose : +//======================================================================= +void Draw_Report::Whatis (Draw_Interpretor& S)const +{ + S << "Draw_Report"; +} diff --git a/src/Draw/Draw_Report.hxx b/src/Draw/Draw_Report.hxx new file mode 100644 index 0000000000..b099c54bc8 --- /dev/null +++ b/src/Draw/Draw_Report.hxx @@ -0,0 +1,69 @@ +// Created on: 2018-06-10 +// 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 _Draw_Report_HeaderFile +#define _Draw_Report_HeaderFile + +#include +#include + +#include +#include +#include +#include + +#include + +class Draw_Report; +DEFINE_STANDARD_HANDLE(Draw_Report, Draw_Drawable3D) + +//! To store nummbers in variables. +class Draw_Report : public Draw_Drawable3D +{ + +public: + + Standard_EXPORT Draw_Report (const Handle(Message_Report)& theReport) : myReport (theReport) {} + + Standard_EXPORT const Handle(Message_Report)& GetReport() const { return myReport; } + + Standard_EXPORT void SetReport (const Handle(Message_Report)& theReport) { myReport = theReport; } + + //! Does nothhing. + Standard_EXPORT void DrawOn (Draw_Display& dis) const Standard_OVERRIDE { (void)dis; } + + //! For variable copy. + Standard_EXPORT virtual Handle(Draw_Drawable3D) Copy() const Standard_OVERRIDE; + + //! For variable dump. + Standard_EXPORT virtual void Dump (Standard_OStream& S) const Standard_OVERRIDE; + + //! For variable whatis command. Set as a result the + //! type of the variable. + Standard_EXPORT virtual void Whatis (Draw_Interpretor& I) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(Draw_Report,Draw_Drawable3D) + +private: + Handle(Message_Report) myReport; +}; + + + + + + + +#endif // _Draw_Report_HeaderFile diff --git a/src/Draw/FILES b/src/Draw/FILES index c43b33613f..568f2d3516 100755 --- a/src/Draw/FILES +++ b/src/Draw/FILES @@ -43,6 +43,7 @@ Draw_Marker2D.hxx Draw_Marker3D.cxx Draw_Marker3D.hxx Draw_MarkerShape.hxx +Draw_MessageCommands.cxx Draw_Number.cxx Draw_Number.hxx Draw_PInterp.hxx @@ -53,6 +54,8 @@ Draw_Printer.hxx Draw_ProgressIndicator.cxx Draw_ProgressIndicator.hxx Draw_Replace.tcl +Draw_Report.cxx +Draw_Report.hxx Draw_Segment2D.cxx Draw_Segment2D.hxx Draw_Segment3D.cxx diff --git a/src/Message/FILES b/src/Message/FILES index fe9884e26d..e52f824502 100755 --- a/src/Message/FILES +++ b/src/Message/FILES @@ -4,17 +4,16 @@ Message_Alert.cxx Message_Alert.hxx Message_AlertExtended.cxx Message_AlertExtended.hxx +Message_Alerts.hxx Message_Algorithm.cxx Message_Algorithm.hxx Message_Algorithm.lxx -Message_Attribute.hxx Message_Attribute.cxx -Message_AttributeObject.hxx +Message_Attribute.hxx Message_AttributeObject.cxx -Message_AttributeVectorOfReal.hxx -Message_AttributeVectorOfReal.cxx -Message_AttributeVectorOfRealVec3.hxx -Message_AttributeVectorOfRealVec3.cxx +Message_AttributeObject.hxx +Message_AttributeVectorOfValues.cxx +Message_AttributeVectorOfValues.hxx Message_CompositeAlerts.cxx Message_CompositeAlerts.hxx Message_ExecStatus.hxx diff --git a/src/Message/Message.cxx b/src/Message/Message.cxx index cbaa470231..fe7d02c180 100644 --- a/src/Message/Message.cxx +++ b/src/Message/Message.cxx @@ -89,3 +89,39 @@ Standard_Boolean Message::GravityFromString (const Standard_CString theGravitySt } return Standard_False; } + +// ======================================================================= +// function : GetPointerInfo +// purpose : +// ======================================================================= +TCollection_AsciiString Message::TransientToString (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) +{ + if (thePointer.IsNull()) + return TCollection_AsciiString(); + + return PointerToString(thePointer.operator->(), isShortInfo); +} + +// ======================================================================= +// function : GetPointerInfo +// purpose : +// ======================================================================= +TCollection_AsciiString Message::PointerToString (const void* thePointer, const bool isShortInfo) +{ + std::ostringstream aPtrStr; + aPtrStr << thePointer; + if (!isShortInfo) + return aPtrStr.str().c_str(); + + TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); + for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) + { + if (anInfoPtr.Value(aSymbolId) != '0') + { + anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); + anInfoPtr.Prepend("0x"); + return anInfoPtr; + } + } + return aPtrStr.str().c_str(); +} diff --git a/src/Message/Message.hxx b/src/Message/Message.hxx index 1d78005932..96feb8de0d 100644 --- a/src/Message/Message.hxx +++ b/src/Message/Message.hxx @@ -83,7 +83,22 @@ public: Standard_EXPORT static Standard_Boolean GravityFromString (const Standard_CString theGravityString, Message_Gravity& theGravity); - + //! Returns separator symbol of Dump information + static Standard_Character DumpSeparator() { 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 + //! \return the string value + Standard_EXPORT static TCollection_AsciiString TransientToString (const Handle(Standard_Transient)& thePointer, + const bool isShortInfo = true); + + //! Convert pointer to string value + //! \param thePointer a pointer + //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped + //! \return the string value + Standard_EXPORT static TCollection_AsciiString PointerToString (const void* thePointer, + const bool isShortInfo = true); protected: diff --git a/src/Message/Message_Alerts.hxx b/src/Message/Message_Alerts.hxx new file mode 100644 index 0000000000..9af6695031 --- /dev/null +++ b/src/Message/Message_Alerts.hxx @@ -0,0 +1,69 @@ +// Created on: 2018-06-10 +// 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 _Message_Alerts_HeaderFile +#define _Message_Alerts_HeaderFile + +#include +#include +#include +#include +#include +#include + +static Handle(Message_Alert) OCCT_Message_Alert; + +#define MESSAGE_INFO(Name, Description, PerfMeter, ParentAlert) \ + { \ + if (!Message_Report::CurrentReport().IsNull() && \ + Message_Report::CurrentReport()->IsActive (Message_Info)) \ + { \ + OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ + new Message_Attribute (Name, Description), PerfMeter, ParentAlert); \ + } \ + } + +#define MESSAGE_INFO_OBJECT(Object, Name, Description, PerfMeter, ParentAlert) \ + { \ + if (!Message_Report::CurrentReport().IsNull() && \ + Message_Report::CurrentReport()->IsActive (Message_Info)) \ + { \ + OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ + new Message_AttributeObject (Object, Name, Description), PerfMeter, ParentAlert ); \ + } \ + } + +#define MESSAGE_INFO_VALUES(StreamValues, Name, Description, PerfMeter, ParentAlert) \ + { \ + if (!Message_Report::CurrentReport().IsNull() && \ + Message_Report::CurrentReport()->IsActive (Message_Info)) \ + { \ + OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ + new Message_AttributeVectorOfValues (StreamValues, Name, Description), PerfMeter, ParentAlert ); \ + } \ + } + +#define DUMP_VALUE(OS, Value) \ + { \ + OS << Value << Message::DumpSeparator(); \ + } + +#define DUMP_VALUES(OS, Value1, Value2) \ + { \ + OS << Value1 << Message::DumpSeparator() << Value2 << Message::DumpSeparator(); \ + } + + +#endif // _Message_Alerts_HeaderFile diff --git a/src/Message/Message_AttributeVectorOfReal.cxx b/src/Message/Message_AttributeVectorOfReal.cxx deleted file mode 100644 index 0880b5b1a2..0000000000 --- a/src/Message/Message_AttributeVectorOfReal.cxx +++ /dev/null @@ -1,68 +0,0 @@ -// Created on: 2018-06-10 -// 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 - -IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeVectorOfReal, Message_Attribute) - -//======================================================================= -//function : Message_AttributeVectorOfReal -//purpose : -//======================================================================= - -Message_AttributeVectorOfReal::Message_AttributeVectorOfReal (const NCollection_Vector& theValues, - const TCollection_AsciiString& theName, - const TCollection_AsciiString& theDescription) -: Message_Attribute(theName, theDescription) -{ - SetValues (theValues); -} - -//======================================================================= -//function : SetValues -//purpose : -//======================================================================= - -void Message_AttributeVectorOfReal::SetValues (const NCollection_Vector& theValues) -{ - myValues = theValues; - - myCachedValue = TCollection_AsciiString ("[") + (Standard_Integer)myValues.Length() + "] : "; - if (myValues.Length() < 2) - return; - - myCachedValue += myValues.First(); - myCachedValue += " ... "; - myCachedValue += myValues.Last(); -} - -//======================================================================= -//function : GetDescription -//purpose : -//======================================================================= - -const TCollection_AsciiString& Message_AttributeVectorOfReal::GetDescription() const -{ - if (!Message_Attribute::GetDescription().IsEmpty()) - return Message_Attribute::GetDescription(); - - return myCachedValue; -} - diff --git a/src/Message/Message_AttributeVectorOfReal.hxx b/src/Message/Message_AttributeVectorOfReal.hxx deleted file mode 100644 index ec0fa52da7..0000000000 --- a/src/Message/Message_AttributeVectorOfReal.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// Created on: 2018-06-10 -// 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 _Message_AttributeVectorOfReal_HeaderFile -#define _Message_AttributeVectorOfReal_HeaderFile - -#include -#include - -#include - -class Message_PerfMeter; -class Message_Report; - -//! Alert object storing container of Standard_Real values in its field -class Message_AttributeVectorOfReal : public Message_Attribute -{ -public: - - //! Constructor with string argument - Standard_EXPORT Message_AttributeVectorOfReal (const NCollection_Vector& theValues, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); - - //! Sets the values - //! @param theValues container of values - Standard_EXPORT void SetValues (const NCollection_Vector& theValues); - - //! Returns values - //! @return values - const NCollection_Vector& GetValues() const { return myValues; } - - //! Returns description of alert if it is set - //! @return alert description - virtual const TCollection_AsciiString& GetDescription() const; - - - // OCCT RTTI - DEFINE_STANDARD_RTTIEXT(Message_AttributeVectorOfReal, Message_Attribute) - -private: - NCollection_Vector myValues; //!< container of values - TCollection_AsciiString myCachedValue; //!< short description of the values in form: [size] : first ... last -}; - -#endif // _Message_AttributeVectorOfReal_HeaderFile diff --git a/src/Message/Message_AttributeVectorOfRealVec3.cxx b/src/Message/Message_AttributeVectorOfRealVec3.cxx deleted file mode 100644 index 36bb716b49..0000000000 --- a/src/Message/Message_AttributeVectorOfRealVec3.cxx +++ /dev/null @@ -1,69 +0,0 @@ -// Created on: 2018-06-10 -// 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 - -IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeVectorOfRealVec3, Message_Attribute) - -//======================================================================= -//function : Message_AttributeVectorOfRealVec3 -//purpose : -//======================================================================= - -Message_AttributeVectorOfRealVec3::Message_AttributeVectorOfRealVec3 (const NCollection_Vector>& theValues, - const TCollection_AsciiString& theName, - const TCollection_AsciiString& theDescription) -: Message_Attribute (theName, theDescription) -{ - SetValues (theValues); -} - -//======================================================================= -//function : SetValues -//purpose : -//======================================================================= - -void Message_AttributeVectorOfRealVec3::SetValues (const NCollection_Vector>& theValues) -{ - myValues = theValues; - - myCachedValue = TCollection_AsciiString ("[") + (Standard_Integer)myValues.Length() + "] : "; - if (myValues.Length() < 2) - return; - - NCollection_Vec3 aValue = myValues.First(); - myCachedValue = myCachedValue + "(" + aValue.x() + "," + aValue.y() + "," + aValue.z() + ")"; - myCachedValue += " ... "; - aValue = myValues.Last(); - myCachedValue = myCachedValue + "(" + aValue.x() + "," + aValue.y() + "," + aValue.z() + ")"; -} - -//======================================================================= -//function : GetDescription -//purpose : -//======================================================================= - -const TCollection_AsciiString& Message_AttributeVectorOfRealVec3::GetDescription() const -{ - if (!Message_Attribute::GetDescription().IsEmpty()) - return Message_Attribute::GetDescription(); - - return myCachedValue; -} - diff --git a/src/Message/Message_AttributeVectorOfRealVec3.hxx b/src/Message/Message_AttributeVectorOfRealVec3.hxx deleted file mode 100644 index b47b80beed..0000000000 --- a/src/Message/Message_AttributeVectorOfRealVec3.hxx +++ /dev/null @@ -1,56 +0,0 @@ -// Created on: 2018-06-10 -// 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 _Message_AttributeVectorOfRealVec3_HeaderFile -#define _Message_AttributeVectorOfRealVec3_HeaderFile - -#include -#include - -#include -#include - -//! Alert object storing container of Standard_Real values in its field -class Message_AttributeVectorOfRealVec3 : public Message_Attribute -{ -public: - - //! Constructor with string argument - Standard_EXPORT Message_AttributeVectorOfRealVec3 (const NCollection_Vector>& theValues, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); - - //! Sets the values - //! @param theValues container of values - Standard_EXPORT void SetValues (const NCollection_Vector>& theValues); - - //! Returns values - //! @return values - const NCollection_Vector>& GetValues() const { return myValues; } - - //! Returns description of alert if it is set - //! @return alert description - virtual const TCollection_AsciiString& GetDescription() const; - - // OCCT RTTI - DEFINE_STANDARD_RTTIEXT(Message_AttributeVectorOfRealVec3, Message_Attribute) - -private: - NCollection_Vector> myValues; //!< container of values - TCollection_AsciiString myCachedValue; - TCollection_AsciiString myDescription; //!< short description of the values in form: [size] : first ... last -}; - -#endif // _Message_AttributeVectorOfRealVec3_HeaderFile diff --git a/src/Message/Message_AttributeVectorOfValues.cxx b/src/Message/Message_AttributeVectorOfValues.cxx new file mode 100644 index 0000000000..fcbb2fc9d2 --- /dev/null +++ b/src/Message/Message_AttributeVectorOfValues.cxx @@ -0,0 +1,118 @@ +// Created on: 2018-06-10 +// 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 + +IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeVectorOfValues, Message_Attribute) + +//======================================================================= +//function : SetValues +//purpose : +//======================================================================= +Message_AttributeVectorOfValues::Message_AttributeVectorOfValues (const Standard_SStream& theStream, + const TCollection_AsciiString& theName, + const TCollection_AsciiString& theDescription) +: Message_Attribute(theName, theDescription) +{ + 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_Integer aRow = 0; + 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 + myValues.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); + } + } + myColumnCount = aColumnCount; +} + +//======================================================================= +//function : SetValues +//purpose : +//======================================================================= + +void Message_AttributeVectorOfValues::SetValues (const NCollection_Vector& theValues) +{ + myValues = theValues; + + int aLength = (Standard_Integer)myValues.Length(); + if (aLength < 2) + return; + + if (myColumnCount <= 0) + myCachedValue = TCollection_AsciiString ("[") + aLength + "] : "; + else + myCachedValue = TCollection_AsciiString ("[") + (aLength / myColumnCount) + ", " + myColumnCount + "] : "; + + myCachedValue += myValues.First(); + myCachedValue += " ... "; + myCachedValue += myValues.Last(); +} + +//======================================================================= +//function : GetDescription +//purpose : +//======================================================================= + +const TCollection_AsciiString& Message_AttributeVectorOfValues::GetDescription() const +{ + if (!Message_Attribute::GetDescription().IsEmpty()) + return Message_Attribute::GetDescription(); + + return myCachedValue; +} + diff --git a/src/Message/Message_AttributeVectorOfValues.hxx b/src/Message/Message_AttributeVectorOfValues.hxx new file mode 100644 index 0000000000..369991da6b --- /dev/null +++ b/src/Message/Message_AttributeVectorOfValues.hxx @@ -0,0 +1,68 @@ +// Created on: 2018-06-10 +// 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 _Message_AttributeVectorOfValues_HeaderFile +#define _Message_AttributeVectorOfValues_HeaderFile + +#include +#include + +#include + +class Message_PerfMeter; +class Message_Report; + +//! Alert object storing container of Standard_Real values in its field +class Message_AttributeVectorOfValues : public Message_Attribute +{ +public: + + //! Constructor with string argument + Standard_EXPORT Message_AttributeVectorOfValues (const Standard_SStream& theStream, + const TCollection_AsciiString& theName = TCollection_AsciiString(), + const TCollection_AsciiString& theDescription = TCollection_AsciiString()); + + //! Sets the values + //! @param theValues container of values + Standard_EXPORT void SetValues (const NCollection_Vector& theValues); + + //! Returns values + //! @return values + const NCollection_Vector& GetValues() const { return myValues; } + + //! Returns description of alert if it is set + //! @return alert description + virtual const TCollection_AsciiString& GetDescription() const; + + + //! Sets value to present values in a table view + //! \param theValue value of division the values on sub-containers + void SetColumnCount (const Standard_Integer& theValue) { myColumnCount = theValue; } + + //! Gets value to present values in a table view + //! \param theSubSize value of division the values on sub-containers + Standard_Integer GetColumnCount() const { return myColumnCount; } + + // OCCT RTTI + DEFINE_STANDARD_RTTIEXT(Message_AttributeVectorOfValues, Message_Attribute) + +private: + NCollection_Vector myValues; //!< container of values + Standard_Integer myColumnCount; //!< value to present container of values into table + + TCollection_AsciiString myCachedValue; //!< short description of the values in form: [size] : first ... last +}; + +#endif // _Message_AttributeVectorOfValues_HeaderFile diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index ab3b9823d3..38f3c3c875 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -26,6 +26,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_Report,Standard_Transient) +static Handle(Message_Report) MyReport; + //======================================================================= //function : Message_Report //purpose : @@ -37,6 +39,18 @@ Message_Report::Message_Report () SetActive (Standard_True); } +//======================================================================= +//function : CurrentReport +//purpose : +//======================================================================= +Handle(Message_Report) Message_Report::CurrentReport(const Standard_Boolean theToCreate) +{ + if (MyReport.IsNull() && theToCreate) + MyReport = new Message_Report(); + + return MyReport; +} + //======================================================================= //function : AddAlert //purpose : diff --git a/src/Message/Message_Report.hxx b/src/Message/Message_Report.hxx index c3b8edf19a..d19c81aae8 100644 --- a/src/Message/Message_Report.hxx +++ b/src/Message/Message_Report.hxx @@ -56,6 +56,11 @@ public: //! Empty constructor Standard_EXPORT Message_Report (); + //! returns the only one instance of Report + //! When theToCreate is true - automatically creates message report when not exist. + //! that has been created. + Standard_EXPORT static Handle(Message_Report) CurrentReport (const Standard_Boolean theToCreate = Standard_False); + //! Add alert with specified gravity. //! This method is thread-safe, i.e. alerts can be added from parallel threads safely. Standard_EXPORT void AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert); diff --git a/src/TopoDS/TopoDS_AlertAttribute.hxx b/src/TopoDS/TopoDS_AlertAttribute.hxx index ed82829e91..115a9ec28e 100644 --- a/src/TopoDS/TopoDS_AlertAttribute.hxx +++ b/src/TopoDS/TopoDS_AlertAttribute.hxx @@ -24,10 +24,9 @@ class TopoDS_AlertAttribute : public Message_Attribute { public: //! Constructor with shape argument - TopoDS_AlertAttribute (const TopoDS_Shape& theShape, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()) - : Message_Attribute (theName, theDescription), myShape (theShape) {} + Standard_EXPORT TopoDS_AlertAttribute (const TopoDS_Shape& theShape, + const TCollection_AsciiString& theName = TCollection_AsciiString(), + const TCollection_AsciiString& theDescription = TCollection_AsciiString()); //! Returns contained shape const TopoDS_Shape& GetShape() const { return myShape; } @@ -39,5 +38,14 @@ private: TopoDS_Shape myShape; }; +#define MESSAGE_INFO_SHAPE(Shape, Name, Description, PerfMeter, ParentAlert) \ + { \ + if (!Message_Report::CurrentReport().IsNull() && \ + Message_Report::CurrentReport()->IsActive (Message_Info)) \ + { \ + OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ + new TopoDS_AlertAttribute (Shape, Name, Description), PerfMeter, ParentAlert); \ + } \ + } #endif // _TopoDS_AlertAttribute_HeaderFile diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx index 8a3512f1e5..6ee08d2cbb 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx @@ -17,8 +17,7 @@ #include #include -#include -#include +#include #include #include @@ -26,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -250,36 +249,18 @@ void XmlDrivers_MessageReportStorage::exportAlertParameters (const Handle(Messag TDataStd_Comment::Set (theAlertLabel, anAttribute->GetDescription()); Standard_CString aDynamicTypeName = anAttribute->DynamicType()->Name(); - if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfReal)->Name()) + if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfValues)->Name()) { - Handle(Message_AttributeVectorOfReal) aRealArrayAlert = Handle(Message_AttributeVectorOfReal)::DownCast (anAttribute); + Handle(Message_AttributeVectorOfValues) aValuesArrayAlert = Handle(Message_AttributeVectorOfValues)::DownCast (anAttribute); // store values - const NCollection_Vector& anArrayValues = aRealArrayAlert->GetValues(); + const NCollection_Vector& anArrayValues = aValuesArrayAlert->GetValues(); // create real list attribute only if there are values in the attribute if (anArrayValues.IsEmpty()) return; int anArraySize = anArrayValues.Length(); - Handle(TDataStd_RealArray) aRealListAttribute = TDataStd_RealArray::Set (theAlertLabel, 0, anArraySize - 1); + Handle(TDataStd_ExtStringArray) aListAttribute = TDataStd_ExtStringArray::Set (theAlertLabel, 0, anArraySize - 1); for (int aValueId = 0; aValueId < anArraySize; aValueId++) - aRealListAttribute->SetValue (aValueId, anArrayValues.Value (aValueId)); - } - else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfRealVec3)->Name()) - { - Handle(Message_AttributeVectorOfRealVec3) aRealArrayAlert = Handle(Message_AttributeVectorOfRealVec3)::DownCast (anAttribute); - // store values - const NCollection_Vector>& anArrayValues = aRealArrayAlert->GetValues(); - // create real list attribute only if there are values in the attribute - if (anArrayValues.IsEmpty()) - return; - int anArraySize = anArrayValues.Length(); - Handle(TDataStd_RealArray) aRealListAttribute = TDataStd_RealArray::Set (theAlertLabel, 0, 3 * anArraySize - 1); - for (int aValueId = 0; aValueId < anArraySize; aValueId++) - { - NCollection_Vec3 aValue = anArrayValues.Value (aValueId); - aRealListAttribute->SetValue (3 * aValueId, aValue.x()); - aRealListAttribute->SetValue (3 * aValueId + 1, aValue.y()); - aRealListAttribute->SetValue (3 * aValueId + 2, aValue.z()); - } + aListAttribute->SetValue (aValueId, anArrayValues.Value (aValueId)); } } @@ -310,42 +291,24 @@ Handle(Message_Alert) XmlDrivers_MessageReportStorage::importAlertParameters (co Handle(Message_Attribute) aMessageAttribute; if (aDynamicTypeName == STANDARD_TYPE (Message_Attribute)->Name()) aMessageAttribute = new Message_Attribute(); - else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfReal)->Name()) + else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfValues)->Name()) { // values - NCollection_Vector anArrayValues; - if (!aParametersLabel.FindAttribute (TDataStd_RealArray::GetID(), anAttribute)) + NCollection_Vector anArrayValues; + if (!aParametersLabel.FindAttribute (TDataStd_ExtStringArray::GetID(), anAttribute)) return Handle(Message_Alert)(); - Handle(TDataStd_RealArray) aValuesAttribute = Handle(TDataStd_RealArray)::DownCast (anAttribute); + Handle(TDataStd_ExtStringArray) aValuesAttribute = Handle(TDataStd_ExtStringArray)::DownCast (anAttribute); if (aValuesAttribute.IsNull()) return Handle(Message_Alert)(); for (int aValueId = aValuesAttribute->Lower(); aValueId <= aValuesAttribute->Upper(); aValueId++) anArrayValues.Append (aValuesAttribute->Value (aValueId)); - aMessageAttribute = new Message_AttributeVectorOfReal (anArrayValues); - } - else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeVectorOfRealVec3)->Name()) - { - // values - NCollection_Vector> anArrayValues; - if (!aParametersLabel.FindAttribute(TDataStd_RealArray::GetID(), anAttribute)) - return Handle(Message_Alert)(); - - Handle(TDataStd_RealArray) aValuesAttribute = Handle(TDataStd_RealArray)::DownCast (anAttribute); - if (aValuesAttribute.IsNull()) - return Handle(Message_Alert)(); - - for (int aValueId = aValuesAttribute->Lower(); aValueId <= aValuesAttribute->Upper(); - aValueId = aValueId + 3) - { - NCollection_Vec3 aValue (aValuesAttribute->Value (aValueId), - aValuesAttribute->Value (aValueId + 1), - aValuesAttribute->Value (aValueId + 2)); - anArrayValues.Append (aValue); - } - aMessageAttribute = new Message_AttributeVectorOfRealVec3 (anArrayValues); + Standard_SStream aStream; + Handle(Message_AttributeVectorOfValues) anAlert = new Message_AttributeVectorOfValues (aStream); + anAlert->SetValues (anArrayValues); + aMessageAttribute = anAlert; } if (!aMessageAttribute.IsNull()) diff --git a/tests/tools/grids.list b/tests/tools/grids.list index c8ade14958..ee623aba26 100644 --- a/tests/tools/grids.list +++ b/tests/tools/grids.list @@ -1,3 +1,4 @@ 001 dfbrowser 001 shapeview 001 vinspector +001 messageview diff --git a/tests/tools/messageview/A1 b/tests/tools/messageview/A1 new file mode 100644 index 0000000000..7351c5f447 --- /dev/null +++ b/tests/tools/messageview/A1 @@ -0,0 +1,12 @@ +pload ALL INSPECTOR +vinit + +activateReport -mode on -gravity info + +box s 200 100 120 +vdisplay s -dispmode 1 +vfit +vselmode 2 1 + +tinspector -plugins shapeview +tinspector -plugins messageview diff --git a/tools/MessageModel/FILES b/tools/MessageModel/FILES index 10dbf13fbe..bb44a4de71 100644 --- a/tools/MessageModel/FILES +++ b/tools/MessageModel/FILES @@ -12,10 +12,8 @@ MessageModel_ItemRoot.cxx MessageModel_ItemRoot.hxx MessageModel_ReportCallBack.cxx MessageModel_ReportCallBack.hxx -MessageModel_TableModelRealValues.cxx -MessageModel_TableModelRealValues.hxx -MessageModel_TableModelRealVec3Values.cxx -MessageModel_TableModelRealVec3Values.hxx +MessageModel_TableModelValues.cxx +MessageModel_TableModelValues.hxx MessageModel_Tools.cxx MessageModel_Tools.hxx MessageModel_TreeModel.cxx diff --git a/tools/MessageModel/MessageModel.qrc b/tools/MessageModel/MessageModel.qrc index b8cc9bd31c..6862cafe7d 100644 --- a/tools/MessageModel/MessageModel.qrc +++ b/tools/MessageModel/MessageModel.qrc @@ -1,7 +1,6 @@ icons/item_shape.png - icons/item_vectorOfReal.png - icons/item_vectorOfRealVec3.png + icons/item_vectorOfValues.png diff --git a/tools/MessageModel/MessageModel_Actions.cxx b/tools/MessageModel/MessageModel_Actions.cxx index 57fde16fa5..1f6f26509c 100644 --- a/tools/MessageModel/MessageModel_Actions.cxx +++ b/tools/MessageModel/MessageModel_Actions.cxx @@ -24,15 +24,19 @@ #include #include +#include + #include -#include +#include +#include #include #include #include #include #include #include +#include // ======================================================================= // function : Constructor @@ -146,7 +150,7 @@ void MessageModel_Actions::OnDeactivateReport() return; aReport->SetActive (Standard_False); - ((MessageModel_TreeModel*)mySelectionModel)->EmitDataChanged (aReportIndex, aReportIndex); + ((MessageModel_TreeModel*)mySelectionModel->model())->EmitDataChanged (aReportIndex, aReportIndex); } // ======================================================================= @@ -161,7 +165,7 @@ void MessageModel_Actions::OnActivateReport() return; aReport->SetActive (Standard_True); - ((MessageModel_TreeModel*)mySelectionModel)->EmitDataChanged (aReportIndex, aReportIndex); + ((MessageModel_TreeModel*)mySelectionModel->model())->EmitDataChanged (aReportIndex, aReportIndex); } // ======================================================================= @@ -199,11 +203,18 @@ void MessageModel_Actions::OnExportToShapeView() if (anAlert.IsNull()) continue; - Handle(TopoDS_AlertWithShape) aShapeAlert = Handle(TopoDS_AlertWithShape)::DownCast (anAlert); - if (aShapeAlert.IsNull() || aShapeAlert->GetShape().IsNull()) + Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (anAlert); + if (anExtAlert.IsNull()) + continue; + + Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); + if (anAttribute.IsNull()) + continue; + + if (!anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) continue; - const TopoDS_Shape aShape = aShapeAlert->GetShape(); + const TopoDS_Shape aShape = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape(); if (aShape.IsNull()) continue; aPluginParameters.Append (aShape.TShape()); diff --git a/tools/MessageModel/MessageModel_Actions.hxx b/tools/MessageModel/MessageModel_Actions.hxx index 3315a9f652..2de60eca78 100644 --- a/tools/MessageModel/MessageModel_Actions.hxx +++ b/tools/MessageModel/MessageModel_Actions.hxx @@ -16,21 +16,19 @@ #ifndef MessageModel_Actions_H #define MessageModel_Actions_H -#ifdef _MSC_VER - #pragma warning(disable : 4127 4718) // conditional expression is constant, recursive call has no side effects -#endif - #include #include #include #include +#include #include #include #include #include #include +#include class Message_Report; class MessageModel_TreeModel; diff --git a/tools/MessageModel/MessageModel_ItemAlert.cxx b/tools/MessageModel/MessageModel_ItemAlert.cxx index f149cf5711..c884a45e53 100644 --- a/tools/MessageModel/MessageModel_ItemAlert.cxx +++ b/tools/MessageModel/MessageModel_ItemAlert.cxx @@ -21,15 +21,16 @@ #include #include -#include -#include +#include #include #include -#include +#include +#include #include #include +#include // ======================================================================= // function : initValue @@ -65,12 +66,16 @@ QVariant MessageModel_ItemAlert::initValue (const int theRole) const // if the alert is composite, process the real alert if (theRole == Qt::DecorationRole && Column() == 0) { - if (anAlert->IsKind (STANDARD_TYPE (TopoDS_AlertWithShape))) + Handle(Message_AlertExtended) anExtAttribute = Handle(Message_AlertExtended)::DownCast (anAlert); + if (anExtAttribute.IsNull()) + return QVariant(); + + Handle(Message_Attribute) anAttribute = anExtAttribute->Attribute(); + + if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) return QIcon (":/icons/item_shape.png"); - else if (anAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfReal))) - return QIcon (":/icons/item_vectorOfReal.png"); - else if (anAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfRealVec3))) - return QIcon (":/icons/item_vectorOfRealVec3.png"); + else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeVectorOfValues))) + return QIcon (":/icons/item_vectorOfValues.png"); else return QVariant(); } diff --git a/tools/MessageModel/MessageModel_ItemAlert.hxx b/tools/MessageModel/MessageModel_ItemAlert.hxx index 9fda8eeddc..3f338c1d0c 100644 --- a/tools/MessageModel/MessageModel_ItemAlert.hxx +++ b/tools/MessageModel/MessageModel_ItemAlert.hxx @@ -23,8 +23,10 @@ #include #include +#include #include #include +#include #include diff --git a/tools/MessageModel/MessageModel_ItemReport.cxx b/tools/MessageModel/MessageModel_ItemReport.cxx index 07bd1be492..2ba14ae1c7 100644 --- a/tools/MessageModel/MessageModel_ItemReport.cxx +++ b/tools/MessageModel/MessageModel_ItemReport.cxx @@ -20,7 +20,9 @@ #include +#include #include +#include // ======================================================================= // function : initValue diff --git a/tools/MessageModel/MessageModel_ItemReport.hxx b/tools/MessageModel/MessageModel_ItemReport.hxx index 067861daec..1c7c081fa7 100644 --- a/tools/MessageModel/MessageModel_ItemReport.hxx +++ b/tools/MessageModel/MessageModel_ItemReport.hxx @@ -21,8 +21,10 @@ #include #include +#include #include #include +#include class MessageModel_ItemReport; typedef QExplicitlySharedDataPointer MessageModel_ItemReportPtr; diff --git a/tools/MessageModel/MessageModel_ItemRoot.cxx b/tools/MessageModel/MessageModel_ItemRoot.cxx index 3d46c1f61c..6165384143 100644 --- a/tools/MessageModel/MessageModel_ItemRoot.cxx +++ b/tools/MessageModel/MessageModel_ItemRoot.cxx @@ -51,6 +51,21 @@ const Handle(Message_Report)& MessageModel_ItemRoot::GetReport (const int theRow return aReportsIt.Value().myReport; } +// ======================================================================= +// function : HasReport +// purpose : +// ======================================================================= +Standard_Boolean MessageModel_ItemRoot::HasReport (const Handle(Message_Report)& theReport) +{ + NCollection_List::Iterator aReportsIt (myReports); + for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++) + { + if (aReportsIt.Value().myReport == theReport) + return Standard_True; + } + return Standard_False; +} + // ======================================================================= // function : initValue // purpose : diff --git a/tools/MessageModel/MessageModel_ItemRoot.hxx b/tools/MessageModel/MessageModel_ItemRoot.hxx index 337576e21d..f98e31b3d4 100644 --- a/tools/MessageModel/MessageModel_ItemRoot.hxx +++ b/tools/MessageModel/MessageModel_ItemRoot.hxx @@ -66,6 +66,11 @@ public: Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport, const TCollection_AsciiString& theReportDescription = ""); + //! Returns true if report exists is in the list of the current reports + //! \param theReport a report instance + //! \return boolen value + Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport); + //! Clears internal container of added reports void RemoveAllReports() { myReports.Clear(); } diff --git a/tools/MessageModel/MessageModel_TableModelRealValues.cxx b/tools/MessageModel/MessageModel_TableModelRealValues.cxx deleted file mode 100644 index 0e16f14c30..0000000000 --- a/tools/MessageModel/MessageModel_TableModelRealValues.cxx +++ /dev/null @@ -1,106 +0,0 @@ -// 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 - -const int REAL_SIGNS = 16; - -// ======================================================================= -// function : Constructor -// purpose : -// ======================================================================= - -MessageModel_TableModelRealValues::MessageModel_TableModelRealValues (const Handle(Message_Attribute)& theAttribute, - const int theSectionWidth) - : myAttribute (Handle(Message_AttributeVectorOfReal)::DownCast (theAttribute)) -{ - SetUseTableProperties (true); - SetUseTablePropertiesXStep (true, -1); - - SetDefaultSectionSize (Qt::Horizontal, theSectionWidth); -} - -// ======================================================================= -// function : ColumnCount -// purpose : -// ======================================================================= - -int MessageModel_TableModelRealValues::ColumnCount (const QModelIndex&) const -{ - return myAttribute->GetValues().Length(); -} - -// ======================================================================= -// function : Data -// purpose : -// ======================================================================= - -QVariant MessageModel_TableModelRealValues::Data (const int, const int theColumn, int theRole) const -{ - if (theRole == Qt::DisplayRole && theColumn < myAttribute->GetValues().Length()) - { - return myAttribute->GetValues().Value(theColumn); - } - - return QVariant(); -} - -// ======================================================================= -// function : GetRangeValues -// purpose : -// ======================================================================= - -void MessageModel_TableModelRealValues::GetRangeValues (QString& theMinValue, QString& theMaxValue, const QModelIndexList& theSelected) const -{ - double aMinValue, aMaxValue; - aMinValue = DBL_MAX; - aMaxValue = DBL_MIN; - - NCollection_Vector aValues = myAttribute->GetValues(); - int aValuesSize = aValues.Length(); - if (aValuesSize < 1) - return; - - if (theSelected.isEmpty()) - { - aMinValue = aMaxValue = aValues.First(); - for (int i = 1; i < aValuesSize; i++) - { - double aValue = aValues.Value (i); - if (aValue < aMinValue) aMinValue = aValue; - if (aValue > aMaxValue) aMaxValue = aValue; - } - } - else - { - ViewControl_TableModel* aModel = (ViewControl_TableModel*)theSelected[0].model(); - int aRow, aColumn; - for (QModelIndexList::const_iterator aSelIt = theSelected.begin(); aSelIt != theSelected.end(); aSelIt++) - { - aModel->GetSourcePosition (*aSelIt, aRow, aColumn); - if (aColumn >= aValuesSize) - continue; - - double aValue = aValues.Value (aColumn); - if (aValue < aMinValue) aMinValue = aValue; - if (aValue > aMaxValue) aMaxValue = aValue; - } - } - - theMinValue = QString::number(aMinValue, 'g', REAL_SIGNS); - theMaxValue = QString::number(aMaxValue, 'g', REAL_SIGNS); -} diff --git a/tools/MessageModel/MessageModel_TableModelRealVec3Values.cxx b/tools/MessageModel/MessageModel_TableModelRealVec3Values.cxx deleted file mode 100644 index 1e653f0d8d..0000000000 --- a/tools/MessageModel/MessageModel_TableModelRealVec3Values.cxx +++ /dev/null @@ -1,122 +0,0 @@ -// 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 : Constructor -// purpose : -// ======================================================================= - -MessageModel_TableModelRealVec3Values::MessageModel_TableModelRealVec3Values (const Handle(Message_Attribute)& theAttribute, - const int theSectionWidth) - : myAttribute (Handle(Message_AttributeVectorOfRealVec3)::DownCast (theAttribute)) -{ - SetUseTableProperties (true); - - SetDefaultSectionSize (Qt::Horizontal, theSectionWidth); -} - -// ======================================================================= -// function : ColumnCount -// purpose : -// ======================================================================= - -int MessageModel_TableModelRealVec3Values::ColumnCount (const QModelIndex&) const -{ - return myAttribute->GetValues().Length(); -} - -// ======================================================================= -// function : Data -// purpose : -// ======================================================================= - -QVariant MessageModel_TableModelRealVec3Values::Data (const int, const int theColumn, int theRole) const -{ - if (theRole != Qt::DisplayRole || theColumn > myAttribute->GetValues().Length()) - return QVariant(); - - NCollection_Vec3 aValue = myAttribute->GetValues().Value(theColumn); - return QString ("%1, %2, %3").arg (aValue.x()).arg (aValue.y()).arg (aValue.z()); -} - -// ======================================================================= -// function : GetRangeValues -// purpose : -// ======================================================================= - -void MessageModel_TableModelRealVec3Values::GetRangeValues (QString& theMinValue, QString& theMaxValue, - const QModelIndexList& theSelected) const -{ - theMinValue = DBL_MAX; - theMaxValue = DBL_MIN; - - QList aValuePositions; - if (!theSelected.isEmpty()) - { - ViewControl_TableModel* aModel = (ViewControl_TableModel*)theSelected[0].model(); - int aRow, aColumn; - for (QModelIndexList::const_iterator aSelIt = theSelected.begin(); aSelIt != theSelected.end(); aSelIt++) - { - aModel->GetSourcePosition (*aSelIt, aRow, aColumn); - aValuePositions.append (aColumn); - } - } - - NCollection_Vector> aValues = myAttribute->GetValues(); - int aValuesSize = aValues.Length(); - if (aValuesSize < 1) - return; - - double aXMinValue = aValues.First().x(), aXMaxValue = aValues.First().x(); - NCollection_Vec3 aValue; - for (int i = 1; i < aValuesSize; i++) - { - if (!aValuePositions.empty() && !aValuePositions.contains (i)) - continue; - - aValue = aValues.Value (i); - if (aValue.x() < aXMinValue) aXMinValue = aValue.x(); - if (aValue.x() > aXMaxValue) aXMaxValue = aValue.x(); - } - - double anYMinValue = aValues.First().y(), anYMaxValue = aValues.First().y(); - for (int i = 1; i < aValuesSize; i++) - { - if (!aValuePositions.empty() && !aValuePositions.contains (i)) - continue; - - aValue = aValues.Value (i); - if (aValue.x() == aXMinValue && aValue.y() < anYMinValue) anYMinValue = aValue.y(); - if (aValue.x() == aXMaxValue && aValue.y() > anYMaxValue) anYMaxValue = aValue.y(); - } - - double aZMinValue = aValues.First().z(), aZMaxValue = aValues.First().z(); - for (int i = 1; i < aValuesSize; i++) - { - if (!aValuePositions.empty() && !aValuePositions.contains (i)) - continue; - aValue = aValues.Value (i); - if (aValue.x() == aXMinValue && aValue.y() == anYMinValue && aValue.z() < aZMinValue) aZMinValue = aValue.z(); - if (aValue.x() == aXMaxValue && aValue.y() == anYMaxValue && aValue.z() > aZMaxValue) aZMaxValue = aValue.z(); - } - - theMinValue = QString ("%1, %2, %3").arg (aXMinValue).arg (anYMinValue).arg (aZMinValue); - theMaxValue = QString ("%1, %2, %3").arg (aXMaxValue).arg (anYMaxValue).arg (aZMaxValue); -} diff --git a/tools/MessageModel/MessageModel_TableModelRealVec3Values.hxx b/tools/MessageModel/MessageModel_TableModelRealVec3Values.hxx deleted file mode 100644 index d10a1de91c..0000000000 --- a/tools/MessageModel/MessageModel_TableModelRealVec3Values.hxx +++ /dev/null @@ -1,67 +0,0 @@ -// 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 MessageModel_TableModelRealVec3Values_H -#define MessageModel_TableModelRealVec3Values_H - -#ifdef _MSC_VER - #pragma warning(disable : 4127 4718) // conditional expression is constant, recursive call has no side effects -#endif - -#include - -#include - -//! \class MessageModel_TableModelRealVec3Values -//! \brief This is an implementation for ViewControl_TableModel to present Message_AttributeVectorOfRealVec3 object -class MessageModel_TableModelRealVec3Values : public ViewControl_TableModelValues -{ -public: - - //! Constructor - Standard_EXPORT MessageModel_TableModelRealVec3Values (const Handle(Message_Attribute)& theAttribute, const int theSectionWidth); - - //! Destructor - virtual ~MessageModel_TableModelRealVec3Values() Standard_OVERRIDE {} - - //! Returns number of columns, size of header values - //! \param theParent an index of the parent item - //! \return an integer value - Standard_EXPORT virtual int ColumnCount (const QModelIndex& theParent = QModelIndex()) const; - - //! 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 - virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const { (void)theParent; return 1; } - - //! 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 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; - - //! Returns minimum and maximum values of selected items or the table content (if selected list is empty) - //! It finds firstly Xmax, then Ymax, after that Zmax. The same for min values. - //! \param theMinValue minimum - //! \param theMaxValue maximum - //! \param theSelected selected cells - virtual void GetRangeValues (QString& theMinValue, QString& theMaxValue, const QModelIndexList& theSelected) const; - -private: - Handle(Message_AttributeVectorOfRealVec3) myAttribute; //!< alert attribute, container of table values -}; - -#endif diff --git a/tools/ViewControl/ViewControl_TableModelFilter.cxx b/tools/MessageModel/MessageModel_TableModelValues.cxx similarity index 53% rename from tools/ViewControl/ViewControl_TableModelFilter.cxx rename to tools/MessageModel/MessageModel_TableModelValues.cxx index 33891475c0..9b295cf8bd 100644 --- a/tools/ViewControl/ViewControl_TableModelFilter.cxx +++ b/tools/MessageModel/MessageModel_TableModelValues.cxx @@ -13,53 +13,63 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include + +#include + +#include + +const int REAL_SIGNS = 16; // ======================================================================= -// function : ColumnCount +// function : Constructor // purpose : // ======================================================================= -int ViewControl_TableModelFilter::ColumnCount (const int theSourceColumnCount) const +MessageModel_TableModelValues::MessageModel_TableModelValues (const Handle(Message_Attribute)& theAttribute, + const int theSectionWidth) + : myAttribute (Handle(Message_AttributeVectorOfValues)::DownCast (theAttribute)) { - return myColumnCount <= 0 ? theSourceColumnCount : myColumnCount; + SetDefaultSectionSize (Qt::Horizontal, theSectionWidth); } // ======================================================================= -// function : RowCount +// function : ColumnCount // purpose : // ======================================================================= -int ViewControl_TableModelFilter::RowCount (const int theSourceColumnCount) const +int MessageModel_TableModelValues::ColumnCount (const QModelIndex&) const { - if (myColumnCount <= 0) - return 1; - - int aRows = (int) (theSourceColumnCount / myColumnCount); - if (myColumnCount > 0 && aRows * myColumnCount < theSourceColumnCount) - aRows++; /// row with left values, not fully filled - - return aRows; + return myAttribute->GetColumnCount(); } // ======================================================================= -// function : GetSourcePosition +// function : RowCount // purpose : // ======================================================================= - -void ViewControl_TableModelFilter::GetSourcePosition (const QModelIndex& theIndex, int& theRow, int& theColumn) const +int MessageModel_TableModelValues::RowCount (const QModelIndex& theParent) const { - GetSourcePosition (theIndex.row(), theIndex.column(), theRow, theColumn); + int aColumnCount = ColumnCount (theParent); + if (!aColumnCount) + return 0; + + return myAttribute->GetValues().Length() / aColumnCount; } // ======================================================================= -// function : GetSourcePosition +// function : Data // purpose : // ======================================================================= -void ViewControl_TableModelFilter::GetSourcePosition (const int theSourceRow, const int theSourceColumn, int& theRow, - int& theColumn) const +QVariant MessageModel_TableModelValues::Data (const int theRow, const int theColumn, int theRole) const { - theRow = 0; - theColumn = myColumnCount * theSourceRow + theSourceColumn; + int aColumnCount = ColumnCount (QModelIndex()); + int anIndex = theRow * aColumnCount + theColumn; + + if (theRole == Qt::DisplayRole && anIndex < myAttribute->GetValues().Length()) + { + return myAttribute->GetValues().Value(anIndex).ToCString(); + } + + return QVariant(); } diff --git a/tools/MessageModel/MessageModel_TableModelRealValues.hxx b/tools/MessageModel/MessageModel_TableModelValues.hxx similarity index 59% rename from tools/MessageModel/MessageModel_TableModelRealValues.hxx rename to tools/MessageModel/MessageModel_TableModelValues.hxx index 346b3bb7c5..85145e78f8 100644 --- a/tools/MessageModel/MessageModel_TableModelRealValues.hxx +++ b/tools/MessageModel/MessageModel_TableModelValues.hxx @@ -13,28 +13,25 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef MessageModel_TableModelRealValues_H -#define MessageModel_TableModelRealValues_H - -#ifdef _MSC_VER - #pragma warning(disable : 4127 4718) // conditional expression is constant, recursive call has no side effects -#endif +#ifndef MessageModel_TableModelValues_H +#define MessageModel_TableModelValues_H #include -#include +#include +class Message_AttributeVectorOfValues; -//! \class MessageModel_TableModelRealValues -//! \brief This is an implementation for ViewControl_TableModel to present Message_AttributeVectorOfReal object -class MessageModel_TableModelRealValues : public ViewControl_TableModelValues +//! \class MessageModel_TableModelValues +//! \brief This is an implementation for ViewControl_TableModel to present Message_AttributeVectorOfValues object +class MessageModel_TableModelValues : public ViewControl_TableModelValues { public: //! Constructor - Standard_EXPORT MessageModel_TableModelRealValues (const Handle(Message_Attribute)& theAttribute, const int theSectionWidth); + Standard_EXPORT MessageModel_TableModelValues (const Handle(Message_Attribute)& theAttribute, const int theSectionWidth); //! Destructor - virtual ~MessageModel_TableModelRealValues() Standard_OVERRIDE {} + virtual ~MessageModel_TableModelValues() Standard_OVERRIDE {} //! Returns number of columns, size of header values //! \param theParent an index of the parent item @@ -44,7 +41,7 @@ public: //! 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 - virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const { (void)theParent; return 1; } + Standard_EXPORT virtual int RowCount (const QModelIndex& theParent) const; //! Returns content of the model index for the given role, it is obtained from internal container of values //! It returns value only for DisplayRole. @@ -53,14 +50,8 @@ public: //! \return value intepreted depending on the given role Standard_EXPORT virtual QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const; - //! Returns minimum and maximum values of selected items or the table content (if selected list is empty) - //! \param theMinValue minimum - //! \param theMaxValue maximum - //! \param theSelected selected cells - virtual void GetRangeValues (QString& theMinValue, QString& theMaxValue, const QModelIndexList& theSelected) const; - private: - Handle(Message_AttributeVectorOfReal) myAttribute; //!< alert attribute, container of table values + Handle(Message_AttributeVectorOfValues) myAttribute; //!< alert attribute, container of table values }; #endif diff --git a/tools/MessageModel/MessageModel_Tools.cxx b/tools/MessageModel/MessageModel_Tools.cxx index 569eabf937..67ac9b5edf 100644 --- a/tools/MessageModel/MessageModel_Tools.cxx +++ b/tools/MessageModel/MessageModel_Tools.cxx @@ -14,11 +14,11 @@ // commercial license or contractual agreement. #include -#include -#include +#include #include #include +#include #include #include @@ -26,10 +26,10 @@ #include #include #include -#include -#include +#include + #include -#include +#include #include // ======================================================================= @@ -65,10 +65,18 @@ TCollection_AsciiString MessageModel_Tools::GetPointerInfo (const Handle(Standar // ======================================================================= TCollection_AsciiString MessageModel_Tools::GetPointerAlertInfo (const Handle(Message_Alert)& theAlert) { - if (theAlert->IsKind (STANDARD_TYPE (TopoDS_AlertWithShape))) - return GetPointerInfo (Handle(TopoDS_AlertWithShape)::DownCast (theAlert)->GetShape().TShape()); - else if (theAlert->IsKind (STANDARD_TYPE (Message_AttributeObject))) - return GetPointerInfo (Handle(Message_AttributeObject)::DownCast (theAlert)->GetObject()); + Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); + if (anExtAlert.IsNull()) + return TCollection_AsciiString(); + + Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); + if (anAttribute.IsNull()) + return TCollection_AsciiString(); + + if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) + return GetPointerInfo (Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape().TShape()); + else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject))) + return GetPointerInfo (Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject()); return TCollection_AsciiString(); } @@ -78,10 +86,17 @@ TCollection_AsciiString MessageModel_Tools::GetPointerAlertInfo (const Handle(Me // ======================================================================= TCollection_AsciiString MessageModel_Tools::GetShapeTypeAlertInfo (const Handle(Message_Alert)& theAlert) { - TopoDS_Shape aShape; + Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); + if (anExtAlert.IsNull()) + return TCollection_AsciiString(); - if (theAlert->IsKind (STANDARD_TYPE (TopoDS_AlertWithShape))) - aShape = Handle(TopoDS_AlertWithShape)::DownCast (theAlert)->GetShape(); + Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); + if (anAttribute.IsNull()) + return TCollection_AsciiString(); + + TopoDS_Shape aShape; + if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) + aShape = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape(); if (aShape.IsNull()) return TCollection_AsciiString(); @@ -98,11 +113,19 @@ TCollection_AsciiString MessageModel_Tools::GetShapeTypeAlertInfo (const Handle( // ======================================================================= TCollection_AsciiString MessageModel_Tools::GetStandardTypeAlertInfo (const Handle(Message_Alert)& theAlert) { + Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); + if (anExtAlert.IsNull()) + return TCollection_AsciiString(); + + Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); + if (anAttribute.IsNull()) + return TCollection_AsciiString(); + Handle(Standard_Transient) aPointer; - if (theAlert->IsKind (STANDARD_TYPE (TopoDS_AlertWithShape))) - aPointer = Handle(TopoDS_AlertWithShape)::DownCast (theAlert)->GetShape().TShape(); - else if (theAlert->IsKind (STANDARD_TYPE (Message_AttributeObject))) - aPointer = Handle(Message_AttributeObject)::DownCast (theAlert)->GetObject(); + if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) + aPointer = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape().TShape(); + else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject))) + aPointer = Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject(); if (aPointer.IsNull()) return TCollection_AsciiString(); @@ -117,8 +140,6 @@ TCollection_AsciiString MessageModel_Tools::GetStandardTypeAlertInfo (const Hand void MessageModel_Tools::GetPropertyTableValues (const Handle(Message_Alert)& theAlert, QList& theTableValues) { - ViewControl_TableModelValues* aTableValues = 0; - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(theAlert); if (anExtendedAlert.IsNull()) return; @@ -127,23 +148,17 @@ void MessageModel_Tools::GetPropertyTableValues (const Handle(Message_Alert)& th if (anAttribute.IsNull()) return; - if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeVectorOfReal))) - { - int aSectionSize = 60; - aTableValues = new MessageModel_TableModelRealValues (anAttribute, aSectionSize); - theTableValues.append (aTableValues); - } - else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeVectorOfRealVec3))) + if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeVectorOfValues))) { - int aSectionSize = 160; - aTableValues = new MessageModel_TableModelRealVec3Values (anAttribute, aSectionSize); + int aSectionSize = 200; + ViewControl_TableModelValues* aTableValues = new MessageModel_TableModelValues (anAttribute, aSectionSize); theTableValues.append (aTableValues); } else { if (!anAttribute->GetDescription().IsEmpty()) { - aTableValues = new ViewControl_TableModelValues(); + ViewControl_TableModelValuesDefault* aTableValues = new ViewControl_TableModelValuesDefault(); QList aHeaderValues; QVector aValues; aHeaderValues << TreeModel_HeaderSection ("Description", -2); @@ -164,76 +179,3 @@ void MessageModel_Tools::GetPropertyTableValues (const Handle(Message_Alert)& th } } } - -// ======================================================================= -// function : BuildShape -// purpose : -// ======================================================================= -TopoDS_Shape MessageModel_Tools::BuildShape (const Handle(Message_Alert)& theAlert, QList theSelectedIndices, ViewControl_Table* theTable) -{ - if (theAlert.IsNull()) - return TopoDS_Shape(); - - BRep_Builder aBuilder; - TopoDS_Compound aCompound; - aBuilder.MakeCompound(aCompound); - - if (theAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfReal))) - { - Handle(Message_AttributeVectorOfReal) aValuesAlert = Handle(Message_AttributeVectorOfReal)::DownCast (theAlert); - NCollection_Vector aValues = aValuesAlert->GetValues(); - int aValuesSize = aValues.Size(); - - gp_Pnt aPreviousPoint(0, 0, 0), aCurrentPoint(0, 0, 0); - double aXStep = theTable->GetProperty()->GetXStep(); - if (aXStep < 0) - aXStep = 1; - double aCurrentXValue = 0; - for (QList::const_iterator anIt = theSelectedIndices.begin(); anIt != theSelectedIndices.end(); anIt++) - { - if (*anIt >= aValuesSize) - continue; - - if (aCurrentXValue == 0) - { //just define the previous point - aPreviousPoint.SetX (aCurrentXValue); - aPreviousPoint.SetY (aValues.Value (*anIt)); - aCurrentXValue = aCurrentXValue + aXStep; - continue; - } - aCurrentPoint.SetX (aCurrentXValue); - aCurrentPoint.SetY (aValues.Value (*anIt)); - if (aPreviousPoint.Distance (aCurrentPoint) < Precision::Confusion()) - continue; - - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge (aPreviousPoint, aCurrentPoint); - aBuilder.Add (aCompound, anEdge); - aPreviousPoint = aCurrentPoint; - aCurrentXValue = aCurrentXValue + aXStep; - } - } - else if (theAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfRealVec3))) - { - Handle(Message_AttributeVectorOfRealVec3) aValuesAlert = Handle(Message_AttributeVectorOfRealVec3)::DownCast (theAlert); - NCollection_Vector> aValues = aValuesAlert->GetValues(); - int aValuesSize = aValues.Size(); - - gp_Pnt aCurrentPoint(0, 0, 0); - NCollection_Vec3 aValue; - for (QList::const_iterator anIt = theSelectedIndices.begin(); anIt != theSelectedIndices.end(); anIt++) - { - if (*anIt >= aValuesSize) - continue; - - aValue = aValues.Value (*anIt); - aCurrentPoint.SetX (aValue.x()); - aCurrentPoint.SetY (aValue.y()); - aCurrentPoint.SetZ (aValue.z()); - - TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex (aCurrentPoint); - aBuilder.Add (aCompound, aVertex); - } - } - - return aCompound; -} diff --git a/tools/MessageModel/MessageModel_Tools.hxx b/tools/MessageModel/MessageModel_Tools.hxx index 58c86a601f..2b63be0061 100644 --- a/tools/MessageModel/MessageModel_Tools.hxx +++ b/tools/MessageModel/MessageModel_Tools.hxx @@ -22,8 +22,9 @@ #include #include +#include #include -//#include +#include class Message_Alert; class ViewControl_TableModelValues; @@ -63,13 +64,6 @@ public: //! \param theTableValue container of values Standard_EXPORT static void GetPropertyTableValues (const Handle(Message_Alert)& theAlert, QList& theTableValues); - - //! Creates TopoDS_Compound with TopoDS_Edge/Vertex on alert data - //! \param theAlert a message alert - //! \parm theSelectedIndices a container of indices - //! \param theTableView source view - Standard_EXPORT TopoDS_Shape static BuildShape (const Handle(Message_Alert)& theAlert, QList aSelectedIndices, - ViewControl_Table* theTableView); }; #endif diff --git a/tools/MessageModel/MessageModel_TreeModel.cxx b/tools/MessageModel/MessageModel_TreeModel.cxx index 84775c4186..7a96f35ff9 100644 --- a/tools/MessageModel/MessageModel_TreeModel.cxx +++ b/tools/MessageModel/MessageModel_TreeModel.cxx @@ -56,6 +56,19 @@ void MessageModel_TreeModel::createRootItem (const int theColumnId) m_pRootItem = myRootItems[0]; } +// ======================================================================= +// function : HasShape +// purpose : +// ======================================================================= +Standard_Boolean MessageModel_TreeModel::HasReport (const Handle(Message_Report)& theReport) +{ + if (columnCount() == 0) + return Standard_False; + + MessageModel_ItemRootPtr aRootItem = itemDynamicCast (RootItem (0)); + return aRootItem && aRootItem->HasReport (theReport); +} + // ======================================================================= // function : AddShape // purpose : diff --git a/tools/MessageModel/MessageModel_TreeModel.hxx b/tools/MessageModel/MessageModel_TreeModel.hxx index 0769fd4473..df32bebb39 100644 --- a/tools/MessageModel/MessageModel_TreeModel.hxx +++ b/tools/MessageModel/MessageModel_TreeModel.hxx @@ -22,8 +22,10 @@ #include #include +#include #include #include +#include class MessageModel_TreeModel; @@ -39,6 +41,11 @@ public: //! Destructor virtual ~MessageModel_TreeModel() Standard_OVERRIDE {}; + //! Returns true if parameter report was added into the model + //! \param theReport a report instance + //! \return boolen value + Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport); + //! Add shape, append it to the model root item //! \param theReport a report instance //! \param theReportDescription an additional report information diff --git a/tools/MessageModel/icons/item_vectorOfValues.png b/tools/MessageModel/icons/item_vectorOfValues.png new file mode 100644 index 0000000000000000000000000000000000000000..7181f9460e4986e85dba66ca426b4cb2797c5a5b GIT binary patch literal 347 zcmeAS@N?(olHy`uVBq!ia0vp^!ayvgcyqV(DCY@~pSZg{#l zhFJ8zonn}G*nr2?K9tvFP1^Uws=fu+3m(U^PtcpV*TMhdX^YuetNWZc2Ai*TW#pIr z6mDnJbbwv6MS+2*tb?^-S*G0a!a3Oix3}dp%v+v$D*E%f*K$E#;oJQy;j9Uh_mVWFKf{g+P3I)AOy z*7$RGM@`;Y*CSmgE(%S2Hb?)kfsbh<$HQGZr={{$unc`-ETA4tmYw)LIL1oR_=r>mdKI;Vst0G)P;+W-In literal 0 HcmV?d00001 diff --git a/tools/MessageModel/icons/item_vectorOfValues.svg b/tools/MessageModel/icons/item_vectorOfValues.svg new file mode 100644 index 0000000000..38b1032701 --- /dev/null +++ b/tools/MessageModel/icons/item_vectorOfValues.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/tools/MessageView/MessageView_VisibilityState.cxx b/tools/MessageView/MessageView_VisibilityState.cxx index db75105fc2..8b4207b8fb 100644 --- a/tools/MessageView/MessageView_VisibilityState.cxx +++ b/tools/MessageView/MessageView_VisibilityState.cxx @@ -17,8 +17,7 @@ #include #include -#include -#include +#include #include @@ -125,7 +124,7 @@ bool MessageView_VisibilityState::hasTableValues (const QModelIndex& theIndex) c if (anAlert.IsNull()) return false; - if (anAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfReal)) || anAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfRealVec3))) + if (anAlert->IsKind (STANDARD_TYPE (Message_AttributeVectorOfValues))) return true; return false; diff --git a/tools/MessageView/MessageView_Window.cxx b/tools/MessageView/MessageView_Window.cxx index 1f778f488e..6f78e0ff91 100644 --- a/tools/MessageView/MessageView_Window.cxx +++ b/tools/MessageView/MessageView_Window.cxx @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -112,6 +111,7 @@ MessageView_Window::MessageView_Window (QWidget* theParent) ((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (MESSAGEVIEW_DEFAULT_TREE_VIEW_WIDTH, MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT)); MessageModel_TreeModel* aModel = new MessageModel_TreeModel (myTreeView); + //aModel->SetReversed (Standard_True); for (int i = 5; i <= 7; i++) // hide shape parameters columns { TreeModel_HeaderSection anItem = aModel->GetHeaderItem (i); @@ -217,7 +217,6 @@ void MessageView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theIt QMap anItems; TreeModel_Tools::SaveState (myTreeView, anItems); View_Tools::SaveState (myViewWindow, anItems); - ViewControl_PropertyView::SaveState (myPropertyView, anItems); for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); @@ -243,8 +242,6 @@ void MessageView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& continue; else if (View_Tools::RestoreState (myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) continue; - else if (ViewControl_PropertyView::RestoreState (myPropertyView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) - continue; } } @@ -274,6 +271,13 @@ void MessageView_Window::UpdateContent() myParameters->SetFileNames (aName, aNames); isUpdated = true; } + Handle(Message_Report) aDefaultReport = Message_Report::CurrentReport( Standard_False); + MessageModel_TreeModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aDefaultReport.IsNull() && !aViewModel->HasReport (aDefaultReport)) + { + aDefaultReport->SetCallBack (myCallBack); + addReport (aDefaultReport); + } // reload report of selected item onReloadReport(); @@ -484,7 +488,7 @@ void MessageView_Window::onPropertyViewSelectionChanged() return; } - TopoDS_Shape aShapeOfSelection = MessageModel_Tools::BuildShape (anAlertItem->GetAlert(), aSelectedIndices[0], aFirstTable); + /*TopoDS_Shape aShapeOfSelection = MessageModel_Tools::BuildShape (anAlertItem->GetAlert(), aSelectedIndices[0], aFirstTable); if (aShapeOfSelection.IsNull()) return; @@ -504,7 +508,7 @@ void MessageView_Window::onPropertyViewSelectionChanged() { anAlertItem->SetCustomShape (aShapeOfSelection); aVisibilityState->SetVisible (anIndex, true); - } + }*/ } // ======================================================================= diff --git a/tools/TreeModel/FILES b/tools/TreeModel/FILES index 2eeab8f369..7bd7cdf3df 100644 --- a/tools/TreeModel/FILES +++ b/tools/TreeModel/FILES @@ -6,6 +6,8 @@ TreeModel_ContextMenu.hxx TreeModel_HeaderSection.hxx TreeModel_ItemBase.cxx TreeModel_ItemBase.hxx +TreeModel_ItemProperties.cxx +TreeModel_ItemProperties.hxx TreeModel_ItemRole.hxx TreeModel_ModelBase.cxx TreeModel_ModelBase.hxx diff --git a/tools/TreeModel/TreeModel_ItemBase.hxx b/tools/TreeModel/TreeModel_ItemBase.hxx index 82ba6dc360..b6c5e5668b 100644 --- a/tools/TreeModel/TreeModel_ItemBase.hxx +++ b/tools/TreeModel/TreeModel_ItemBase.hxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -127,6 +128,12 @@ public: //! \return the row count int rowCount() const { return cachedValue(TreeModel_ItemRole_RowCountRole).toInt(); } + //! Sets item table properties builder + void SetProperties (const Handle(TreeModel_ItemProperties)& theProperties) { myProperties = theProperties; } + + //! Returns item table properties builder + Handle(TreeModel_ItemProperties) GetProperties() const { return myProperties; } + protected: //! \param theParent the parent item @@ -168,6 +175,8 @@ private: int m_iRow; //!< the item row position in the parent item int m_iColumn; //!< the item column position in the parent item bool m_bInitialized; //!< the state whether the item content is already initialized + + Handle(TreeModel_ItemProperties) myProperties; //!< item properties }; //! Returns an explicitly shared pointer to the pointer held by other, using a diff --git a/tools/TreeModel/TreeModel_ItemProperties.cxx b/tools/TreeModel/TreeModel_ItemProperties.cxx new file mode 100644 index 0000000000..628ee6748c --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemProperties.cxx @@ -0,0 +1,18 @@ +// Created on: 2019-02-25 +// 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 + +IMPLEMENT_STANDARD_RTTIEXT(TreeModel_ItemProperties, Standard_Transient) diff --git a/tools/TreeModel/TreeModel_ItemProperties.hxx b/tools/TreeModel/TreeModel_ItemProperties.hxx new file mode 100644 index 0000000000..d9a05c5484 --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemProperties.hxx @@ -0,0 +1,86 @@ +// Created on: 2019-02-25 +// 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 TreeModel_ItemProperties_H +#define TreeModel_ItemProperties_H + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +DEFINE_STANDARD_HANDLE (TreeModel_ItemProperties, Standard_Transient) + +//! \class TreeModel_ItemProperties +//! Class to manipulate properties of tree item. The properties are organized in table structure +class TreeModel_ItemProperties : public Standard_Transient +{ +public: + //! Constructor + TreeModel_ItemProperties() {} + + //! Destructor + ~TreeModel_ItemProperties() {} + + //! Returns number of table rows + //! \return an integer value + virtual int GetTableColumnCount() const { return 2; } + + //! Returns number of table rows + //! \return an integer value + virtual int GetTableRowCount() const { return 0; } + + //! 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 GetTableEditType (const int theRow, const int theColumn) const + { (void)theRow; (void)theColumn; return ViewControl_EditType_None; } + + //! Returns container of string values for enumeration in the model row + //! \param theRow table model row index + //! \param theColumn a model index column + //! \return string values for the enumeration presented in the row or an empty container + virtual QList GetTableEnumValues (const int theRow, const int theColumn) const + { (void)theRow; (void)theColumn; return QList(); } + + //! 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 + { (void)theRow; (void)theColumn; (void)theRole; return QVariant(); } + + //! Sets the value into the table cell. Only 1st column value might be modified. + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theValue a new cell value + virtual bool SetTableData (const int theRow, const int theColumn, const QVariant& theValue) + { (void)theRow; (void)theColumn; (void)theValue; return false; } + + DEFINE_STANDARD_RTTIEXT (TreeModel_ItemProperties, Standard_Transient) +}; + +#endif \ No newline at end of file diff --git a/tools/TreeModel/TreeModel_ModelBase.cxx b/tools/TreeModel/TreeModel_ModelBase.cxx index abc31ab1b0..2840fc829d 100644 --- a/tools/TreeModel/TreeModel_ModelBase.cxx +++ b/tools/TreeModel/TreeModel_ModelBase.cxx @@ -31,6 +31,8 @@ TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent) : QAbstractItemModel (theParent), m_pRootItem (0), m_pUseVisibilityColumn (false), myVisibilityState (0) { + myVisibleIcon = QIcon (":/icons/item_visible.png"); + myInvisibleIcon = QIcon (":/icons/item_invisible.png"); } // ======================================================================= @@ -104,14 +106,18 @@ QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) co if (!myVisibilityState || !myVisibilityState->CanBeVisible (theIndex)) return QVariant(); - QVariant aValue = QIcon (myVisibilityState->IsVisible (theIndex) ? ":/icons/item_visible.png" - : ":/icons/item_invisible.png"); + QVariant aValue = myVisibilityState->IsVisible (theIndex) ? myVisibleIcon : myInvisibleIcon; anItem->SetCustomData (aValue, theRole); return aValue; } TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex); - return anItem->data (theIndex, theRole); + QVariant anItemData = anItem->data (theIndex, theRole); + + if (anItemData.isNull() && theRole == Qt::BackgroundRole && myHighlightedIndices.contains (theIndex)) + anItemData = TreeModel_Tools::LightHighlightColor(); + + return anItemData; } // ======================================================================= diff --git a/tools/TreeModel/TreeModel_ModelBase.hxx b/tools/TreeModel/TreeModel_ModelBase.hxx index 61f0073068..b2eb8bc23b 100644 --- a/tools/TreeModel/TreeModel_ModelBase.hxx +++ b/tools/TreeModel/TreeModel_ModelBase.hxx @@ -84,6 +84,13 @@ public: //!< \return the checker interface TreeModel_VisibilityState* GetVisibilityState () const { return myVisibilityState; } + //! Returns true if the tree view model contains highlighted items. This highlight is set manually. + bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); } + + //! Sets items of the indices highlighted in the model. + //! \param theIndices a list of tree model indices + void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; } + //! Returns the index of the item in the model specified by the given row, column and parent index. //! Saves an internal pointer at the createIndex. This pointer is a shared pointer to the class, //! that realizes a base item interface. If the parent is invalid, a root item is used, otherwise a new item @@ -187,6 +194,10 @@ protected: bool m_pUseVisibilityColumn; //!< the state whether column=0 is reserved for Visibility state TreeModel_VisibilityState* myVisibilityState; //!< the interface of item visibility + QIcon myVisibleIcon; //!< icon of visible state + QIcon myInvisibleIcon; //!< icon of invisible state + + QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted }; #endif diff --git a/tools/TreeModel/TreeModel_Tools.cxx b/tools/TreeModel/TreeModel_Tools.cxx index c1b217b529..7c89df6902 100644 --- a/tools/TreeModel/TreeModel_Tools.cxx +++ b/tools/TreeModel/TreeModel_Tools.cxx @@ -211,3 +211,53 @@ QString TreeModel_Tools::CutString (const QString& theText, const int theWidth, return aLength < theText.length() ? theText.mid (0, aLength) + theTail : theText; } + +// ======================================================================= +// function : LightHighlightColor +// purpose : +// ======================================================================= +QColor TreeModel_Tools::LightHighlightColor() +{ + QWidget aWidget; + QPalette aPalette = aWidget.palette(); + return aPalette.highlight().color().lighter(); +} + +// ======================================================================= +// function : SetExpandedTo +// purpose : +// ======================================================================= +void TreeModel_Tools::SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex) +{ + QAbstractItemModel* aModel = theTreeView->model(); + + QModelIndex aParent = aModel->parent (theIndex); + while (aParent.isValid()) + { + theTreeView->setExpanded (aParent, true); + aParent = aModel->parent (aParent); + } +} + +// ======================================================================= +// function : setExpanded +// purpose : +// ======================================================================= +void TreeModel_Tools::SetExpanded (QTreeView* theTreeView, const QModelIndex& theIndex, const bool isExpanded, + int& theLevels) +{ + bool isToExpand = theLevels == -1 || theLevels > 0; + if (!isToExpand) + return; + + theTreeView->setExpanded (theIndex, isExpanded); + if (theLevels != -1) + theLevels--; + + QAbstractItemModel* aModel = theTreeView->model(); + for (int aRowId = 0, aRows = aModel->rowCount (theIndex); aRowId < aRows; aRowId++) + { + int aLevels = theLevels; + SetExpanded (theTreeView, aModel->index (aRowId, 0, theIndex), isExpanded, aLevels); + } +} diff --git a/tools/TreeModel/TreeModel_Tools.hxx b/tools/TreeModel/TreeModel_Tools.hxx index 39047a2f03..1f24f94ec1 100644 --- a/tools/TreeModel/TreeModel_Tools.hxx +++ b/tools/TreeModel/TreeModel_Tools.hxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,24 @@ public: //! \param theWidth width value, if -1, default value is used //! \param theTail symbols added to the end of the cut string Standard_EXPORT static QString CutString (const QString& theText, const int theWidth = -1, const QString& theTail = "..."); + + //! Returns light highlight color + //! \returns Qt color + Standard_EXPORT static QColor LightHighlightColor(); + + //! Makes the view expanded fron the root till the index + Standard_EXPORT static void SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex); + + //! Recursive items expanding in tree view staring from the index + //! \param theTreeView an OCAF tree view + //! \param theParentIndex an index which children should be expanded + //! \param isExpanded a boolean state if the item should be expanded or collapsed + //! \param theLevels a number of levels to be expanded, or -1 for all levels + Standard_EXPORT static void SetExpanded (QTreeView* theTreeView, + const QModelIndex& theIndex, + const bool isExpanded, + int& theLevels); + }; #endif diff --git a/tools/VInspector/VInspector_TableModelValues.cxx b/tools/VInspector/VInspector_TableModelValues.cxx index 5a32b115f3..bac85b01e8 100644 --- a/tools/VInspector/VInspector_TableModelValues.cxx +++ b/tools/VInspector/VInspector_TableModelValues.cxx @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -42,10 +41,6 @@ VInspector_TableModelValues::VInspector_TableModelValues (const TreeModel_ItemBa SetHeaderVisible(Qt::Horizontal, Standard_False); SetHeaderVisible(Qt::Vertical, Standard_False); - - SetUseTableSeparateSize (false); - SetUseTableProperties (false); - SetUseTablePropertiesXStep (false, -1); } // ======================================================================= @@ -142,31 +137,6 @@ Qt::ItemFlags VInspector_TableModelValues::Flags (const QModelIndex& theIndex) c return aFlags; } -// ======================================================================= -// function : GetRangeValues -// purpose : -// ======================================================================= - -int VInspector_TableModelValues::GetValuesCount () const -{ - VInspector_ItemBasePtr anItem = GetItem(); - - int aRowCount = anItem->GetTableRowCount(); - Handle(Standard_Transient) anObject = anItem->GetObject(); - if (anObject.IsNull()) - return aRowCount * 2; - - for (NCollection_List::Iterator anIterator (myCreators); anIterator.More(); anIterator.Next()) - { - Handle(ViewControl_PaneCreator) aCreator = anIterator.Value(); - ViewControl_Pane* aPane = aCreator->GetPane (anObject->DynamicType()->Name()); - if (!aPane) - continue; - aRowCount += aPane->GetTableRowCount (anObject); - } - return aRowCount * 2; -} - // ======================================================================= // function : GetEditType // purpose : diff --git a/tools/VInspector/VInspector_TableModelValues.hxx b/tools/VInspector/VInspector_TableModelValues.hxx index bb5adc26a8..fcc68c3cf4 100644 --- a/tools/VInspector/VInspector_TableModelValues.hxx +++ b/tools/VInspector/VInspector_TableModelValues.hxx @@ -17,7 +17,6 @@ #define VInspector_TableModelValues_H #include -#include #include #include @@ -66,11 +65,6 @@ public: //! \return flags virtual Qt::ItemFlags Flags (const QModelIndex& theIndex) const Standard_OVERRIDE; - //! 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 - virtual int GetValuesCount () const Standard_OVERRIDE; - //! 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 diff --git a/tools/ViewControl/FILES b/tools/ViewControl/FILES index fea2316f18..8efb5920cb 100644 --- a/tools/ViewControl/FILES +++ b/tools/ViewControl/FILES @@ -16,12 +16,10 @@ ViewControl_TableItemDelegate.cxx ViewControl_TableItemDelegate.hxx ViewControl_TableModel.cxx ViewControl_TableModel.hxx -ViewControl_TableModelFilter.cxx -ViewControl_TableModelFilter.hxx ViewControl_TableModelValues.cxx ViewControl_TableModelValues.hxx -ViewControl_TableProperty.cxx -ViewControl_TableProperty.hxx +ViewControl_TableModelValuesDefault.cxx +ViewControl_TableModelValuesDefault.hxx ViewControl_Tools.cxx ViewControl_Tools.hxx ViewControl_TreeView.hxx diff --git a/tools/ViewControl/ViewControl_ColorSelector.cxx b/tools/ViewControl/ViewControl_ColorSelector.cxx index 5129c89d96..efaf568794 100644 --- a/tools/ViewControl/ViewControl_ColorSelector.cxx +++ b/tools/ViewControl/ViewControl_ColorSelector.cxx @@ -20,7 +20,7 @@ #include #include -#include +//#include #include #include @@ -85,7 +85,7 @@ public: return QVariant ("Name"); Quantity_NameOfColor aColorName; if (ViewControl_ColorSelector::IsExactColorName(myColor, aColorName)) - return Quantity::NameOfColorToString (aColorName); + return "";//Quantity::NameOfColorToString (aColorName); } break; case 2: return isFirstColumn ? QVariant ("Red") : ViewControl_Tools::ToVariant (myColor.GetRGB().Red()); @@ -93,7 +93,7 @@ public: case 4: return isFirstColumn ? QVariant ("Blue") : ViewControl_Tools::ToVariant (myColor.GetRGB().Blue()); case 5: return isFirstColumn ? QVariant ("Alpha") : ViewControl_Tools::ToVariant (myColor.Alpha()); case 6: return isFirstColumn ? QVariant ("Near Name") - : Quantity::NameOfColorToString (myColor.GetRGB().Name()); + : "";//Quantity::NameOfColorToString (myColor.GetRGB().Name()); } return QVariant(); } @@ -236,8 +236,8 @@ public: return QVariant(); if (theRole == Qt::ToolTipRole) - return QString("%1 (%2)").arg(Quantity::NameOfColorToString (aNameOfColor)) - .arg (ViewControl_ColorSelector::ColorToString (Quantity_Color (aNameOfColor))); + return "";//QString("%1 (%2)").arg(Quantity::NameOfColorToString (aNameOfColor)) + // .arg (ViewControl_ColorSelector::ColorToString (Quantity_Color (aNameOfColor))); return QVariant(); } diff --git a/tools/ViewControl/ViewControl_EditType.hxx b/tools/ViewControl/ViewControl_EditType.hxx index 99e2229ba3..2a095c378a 100644 --- a/tools/ViewControl/ViewControl_EditType.hxx +++ b/tools/ViewControl/ViewControl_EditType.hxx @@ -26,7 +26,8 @@ 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_DoubleVec3, //!< control to enter three double values + ViewControl_EditType_DoAction //!< control to perform the row action }; #endif diff --git a/tools/ViewControl/ViewControl_PropertyView.cxx b/tools/ViewControl/ViewControl_PropertyView.cxx index e09527e53b..f2f20c9213 100644 --- a/tools/ViewControl/ViewControl_PropertyView.cxx +++ b/tools/ViewControl/ViewControl_PropertyView.cxx @@ -198,13 +198,6 @@ ViewControl_Table* ViewControl_PropertyView::findTable (const int theTableId, co connect (aTable->GetTableView()->selectionModel(), SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(onTableSelectionChanged (const QItemSelection&, const QItemSelection&))); - connect (aTable->GetProperty(), SIGNAL (propertyChanged()), this, SIGNAL (propertyViewSelectionChanged())); - - if (myXStepValues.size() > theTableId) - aTable->GetProperty()->SetXStep (myXStepValues[theTableId]); - - if (myDivideValues.size() > theTableId) - aTable->GetProperty()->SetDivideSize (myDivideValues[theTableId]); myTableWidgetLayout->addWidget (aTable->GetControl()); @@ -224,58 +217,3 @@ void ViewControl_PropertyView::onTableSelectionChanged (const QItemSelection&, c emit propertyViewSelectionChanged(); } - -// ======================================================================= -// function : SaveState -// purpose : -// ======================================================================= -void ViewControl_PropertyView::SaveState (ViewControl_PropertyView* theView, - QMap& theItems, - const QString& thePrefix) -{ - QList anActiveTables; - theView->GetActiveTables(anActiveTables); - - if (anActiveTables.size() == 0) - return; - - anActiveTables[0]->GetProperty()->GetXStep(); - QStringList aDivideSizes, aXSteps; - for (int i = 0; i < anActiveTables.size(); i++) - { - aXSteps.append (QString::number (anActiveTables[i]->GetProperty()->GetXStep())); - aDivideSizes.append (QString::number (anActiveTables[i]->GetProperty()->GetDivideSize())); - } - theItems[thePrefix + "property_view_xstep_value"] = aXSteps.join (","); - theItems[thePrefix + "property_view_divide_value"] = aDivideSizes.join (","); -} - -// ======================================================================= -// function : RestoreState -// purpose : -// ======================================================================= -bool ViewControl_PropertyView::RestoreState (ViewControl_PropertyView* theView, - const QString& theKey, - const QString& theValue, - const QString& thePrefix) -{ - if (theKey == thePrefix + "property_view_xstep_value") - { - QList aXStepValues; - QStringList aValues = theValue.split (",", QString::SkipEmptyParts); - for (int aValueId = 0; aValueId < aValues.size(); aValueId++) - aXStepValues.append (aValues.at (aValueId).toDouble()); - theView->SetXSteps (aXStepValues); - } - else if (theKey == thePrefix + "property_view_divide_value") - { - QList aDivideValues; - QStringList aValues = theValue.split (",", QString::SkipEmptyParts); - for (int aValueId = 0; aValueId < aValues.size(); aValueId++) - aDivideValues.append (aValues.at (aValueId).toInt()); - theView->SetDivideValues (aDivideValues); - } - else - return false; - return true; -} diff --git a/tools/ViewControl/ViewControl_PropertyView.hxx b/tools/ViewControl/ViewControl_PropertyView.hxx index 1a82c21817..2cb6f75377 100644 --- a/tools/ViewControl/ViewControl_PropertyView.hxx +++ b/tools/ViewControl/ViewControl_PropertyView.hxx @@ -68,31 +68,6 @@ public: //! Clears selection in active tables Standard_EXPORT void ClearActiveTablesSelection(); - //! Sets X steps values for table properties - //! \param container of values - void SetXSteps (const QList& theValues) { myXStepValues = theValues; } - - //! Sets divide values for table properties - //! \param container of values - void SetDivideValues (const QList& theValues) { myDivideValues = theValues; } - - //! Save state of three view in a container in form: key, value. It saves: - //! - XStep of property table - //! - divide values of property table - //! \param theTreeView a view instance - //! \param theItems [out] properties - //! \param thePrefix peference item prefix - Standard_EXPORT static void SaveState (ViewControl_PropertyView* theView, 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 (ViewControl_PropertyView* theView, const QString& theKey, const QString& theValue, - const QString& thePrefix = QString()); - signals: void propertyViewSelectionChanged(); @@ -120,8 +95,5 @@ private: QVBoxLayout* myTableWidgetLayout; //! main view layout where tables or custom widgets are presented QList myTables; //!< table view, shown only first tables filled in Init method QWidget* myCustomWidget; //!< custom view widget - - QList myXStepValues; //! predefined values for XStep in ViewControl_TableProperty - QList myDivideValues; //! predefined values for divide value in ViewControl_TableProperty }; #endif diff --git a/tools/ViewControl/ViewControl_Table.cxx b/tools/ViewControl/ViewControl_Table.cxx index 9975924ebc..19f866acfc 100644 --- a/tools/ViewControl/ViewControl_Table.cxx +++ b/tools/ViewControl/ViewControl_Table.cxx @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include @@ -44,9 +44,6 @@ ViewControl_Table::ViewControl_Table (QWidget* theParent) QGridLayout* aLayout = new QGridLayout (myMainWidget); aLayout->setContentsMargins (0, 0, 0, 0); - myProperty = new ViewControl_TableProperty(myMainWidget, this); - aLayout->addWidget (myProperty->GetControl()); - myTableView = new QTableView (myMainWidget); myTableView->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel); @@ -57,7 +54,6 @@ ViewControl_Table::ViewControl_Table (QWidget* theParent) aVHeader->setDefaultSectionSize (aDefCellSize); aLayout->addWidget (myTableView); - aLayout->addWidget (myProperty->GetInformationControl()); } // ======================================================================= @@ -72,8 +68,6 @@ void ViewControl_Table::SetModel (QAbstractTableModel* theModel) myTableView->setSelectionMode(QAbstractItemView::ExtendedSelection); QItemSelectionModel* aSelectionModel = new QItemSelectionModel(theModel); myTableView->setSelectionModel (aSelectionModel); - connect(aSelectionModel, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, SLOT(onTableSelectionChanged(const QItemSelection&, const QItemSelection&))); } // ======================================================================= @@ -88,9 +82,6 @@ void ViewControl_Table::Init (ViewControl_TableModelValues* theModelValues) ViewControl_TableModel* aModel = dynamic_cast (myTableView->model()); aModel->SetModelValues (theModelValues); - myProperty->SetActive (theModelValues->UseTableProperties()); - myProperty->Init(); - ViewControl_TableItemDelegate* aDelegate = dynamic_cast(myTableView->itemDelegate()); aDelegate->SetModelValues (theModelValues); @@ -123,8 +114,6 @@ void ViewControl_Table::GetSelectedIndices (QMap>& theSelectedIn int aRow, aColumn; for (QModelIndexList::const_iterator anIt = aSelected.begin(); anIt != aSelected.end(); anIt++) { - aModel->GetSourcePosition (*anIt, aRow, aColumn); - if (!theSelectedIndices.contains (aRow)) theSelectedIndices.insert (aRow, QList()); theSelectedIndices[aRow].append (aColumn); @@ -132,13 +121,11 @@ void ViewControl_Table::GetSelectedIndices (QMap>& theSelectedIn } // ======================================================================= -// function : onTableSelectionChanged +// function : SeparatorData // purpose : // ======================================================================= -void ViewControl_Table::onTableSelectionChanged(const QItemSelection&, const QItemSelection&) +QString ViewControl_Table::SeparatorData() { - QModelIndexList aSelected = myTableView->selectionModel()->selectedIndexes(); - - myProperty->UpdateOnTableSelectionChanged(); + return ViewControl_Tools::TableSeparator(); } diff --git a/tools/ViewControl/ViewControl_Table.hxx b/tools/ViewControl/ViewControl_Table.hxx index c4f93f26d0..336f277441 100644 --- a/tools/ViewControl/ViewControl_Table.hxx +++ b/tools/ViewControl/ViewControl_Table.hxx @@ -19,8 +19,6 @@ #include #include -#include - #include #include #include @@ -68,24 +66,13 @@ public: //! \return the table view QTableView* GetTableView() const { return myTableView; } - //! Returns instance of table property control - //! \return property - ViewControl_TableProperty* GetProperty() const { return myProperty; } - //! Retuns model indices of the selected cells in table view //! \param theSelectedIndices [out] a container of indices: row to list of columns Standard_EXPORT void GetSelectedIndices (QMap>& aSelectedIndices); //! Returns text of separation row in table //! \return string value - static QString SeparatorData() { return "---------------------------"; } - -protected slots: - - //! Updates controls by selection change in table view - //! \param theSelected container of selected table cells - //! \param theDeselected container of selected table cells - void onTableSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); + Standard_EXPORT static QString SeparatorData(); private: bool myIsActive; //!< true if the table is used in property view and visible @@ -93,7 +80,5 @@ private: QWidget* myMainWidget; //!< parent of all controls bool myIsUseProperty; //!< boolean value whether the property control should be shown/hidden QTableView* myTableView; //!< table view - - ViewControl_TableProperty* myProperty; //!< modifier of the table visual properties }; #endif diff --git a/tools/ViewControl/ViewControl_TableItemDelegate.cxx b/tools/ViewControl/ViewControl_TableItemDelegate.cxx index ba7558e026..5696212d9d 100644 --- a/tools/ViewControl/ViewControl_TableItemDelegate.cxx +++ b/tools/ViewControl/ViewControl_TableItemDelegate.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -49,8 +50,8 @@ QWidget* ViewControl_TableItemDelegate::createEditor (QWidget* theParent, if (!myModelValues) return 0; - int aRow, aColumn; - myModelValues->GetSourcePosition (theIndex.row(), theIndex.column(), aRow, aColumn); + int aRow = theIndex.row(); + int aColumn = theIndex.column(); ViewControl_EditType anEditType = myModelValues->GetEditType (aRow, aColumn); QWidget* anEditor = createEditorControl (theParent, anEditType); @@ -68,8 +69,8 @@ void ViewControl_TableItemDelegate::setEditorData (QWidget* theEditor, const QMo if (!myModelValues) return; - int aRow, aColumn; - myModelValues->GetSourcePosition (theIndex.row(), theIndex.column(), aRow, aColumn); + int aRow = theIndex.row(); + int aColumn = theIndex.column(); ViewControl_EditType anEditType = myModelValues->GetEditType (aRow, aColumn); setEditorValue (theEditor, anEditType, theIndex.model()->data(theIndex)); @@ -86,8 +87,8 @@ void ViewControl_TableItemDelegate::setModelData (QWidget* theEditor, QAbstractI if (!myModelValues) return; - int aRow, aColumn; - myModelValues->GetSourcePosition (theIndex.row(), theIndex.column(), aRow, aColumn); + int aRow = theIndex.row(); + int aColumn = theIndex.column(); ViewControl_EditType anEditType = myModelValues->GetEditType (aRow, aColumn); theModel->setData (theIndex, getEditorValue (theEditor, anEditType)); @@ -113,7 +114,13 @@ QWidget* ViewControl_TableItemDelegate::createEditorControl (QWidget* theParent, return aLineEdit; } case ViewControl_EditType_Line: return new QLineEdit (theParent); - case ViewControl_EditType_Spin: return new QSpinBox (theParent); + case ViewControl_EditType_Spin: + { + QSpinBox* aSpinBox = new QSpinBox (theParent); + aSpinBox->setRange (IntegerFirst(), IntegerLast()); + return aSpinBox; + } + case ViewControl_EditType_DoAction: return new QPushButton (theParent); default: return 0; } @@ -177,6 +184,7 @@ void ViewControl_TableItemDelegate::setEditorValue (QWidget* theEditor, const Vi case ViewControl_EditType_Double: 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; default: break; } @@ -198,6 +206,7 @@ QVariant ViewControl_TableItemDelegate::getEditorValue (QWidget* theEditor, cons case ViewControl_EditType_Double: 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"); default: return QVariant(); } diff --git a/tools/ViewControl/ViewControl_TableModel.cxx b/tools/ViewControl/ViewControl_TableModel.cxx index 511d39f013..c3b43209b8 100644 --- a/tools/ViewControl/ViewControl_TableModel.cxx +++ b/tools/ViewControl/ViewControl_TableModel.cxx @@ -25,7 +25,6 @@ void ViewControl_TableModel::SetModelValues (ViewControl_TableModelValues* theMo delete myModelValues; myModelValues = theModelValues; - SetFilter(0); } // ======================================================================= @@ -37,8 +36,7 @@ int ViewControl_TableModel::columnCount(const QModelIndex& theParent) const if (!myModelValues) return 0; - int aColumnCount = myModelValues->ColumnCount (theParent); - return isFilterActive() ? myFilter->ColumnCount (aColumnCount) : aColumnCount; + return myModelValues->ColumnCount (theParent); } // ======================================================================= @@ -50,8 +48,7 @@ int ViewControl_TableModel::rowCount(const QModelIndex& theParent ) const if (!myModelValues) return 0; - return isFilterActive() ? myFilter->RowCount (myModelValues->ColumnCount (theParent)) - : myModelValues->RowCount (theParent); + return myModelValues->RowCount (theParent); } // ======================================================================= @@ -64,9 +61,6 @@ QVariant ViewControl_TableModel::data (const QModelIndex& theIndex, int theRole) return QVariant(); int aRow = theIndex.row(), aColumn = theIndex.column(); - if (isFilterActive()) - myFilter->GetSourcePosition (theIndex, aRow, aColumn); - return myModelValues->Data (aRow, aColumn, theRole); } @@ -80,20 +74,5 @@ bool ViewControl_TableModel::setData (const QModelIndex& theIndex, const QVarian return false; int aRow = theIndex.row(), aColumn = theIndex.column(); - if (isFilterActive()) - myFilter->GetSourcePosition (theIndex, aRow, aColumn); - return myModelValues->SetData (aRow, aColumn, theValue, theRole); } - -// ======================================================================= -// function : GetSourcePosition -// purpose : -// ======================================================================= -void ViewControl_TableModel::GetSourcePosition (const QModelIndex& theIndex, int& theRow, int& theColumn) -{ - if (isFilterActive()) - myFilter->GetSourcePosition (theIndex, theRow, theColumn); - else - myModelValues->GetSourcePosition (theIndex.row(), theIndex.column(), theRow, theColumn); -} diff --git a/tools/ViewControl/ViewControl_TableModel.hxx b/tools/ViewControl/ViewControl_TableModel.hxx index aff5e39119..d0459ea68e 100644 --- a/tools/ViewControl/ViewControl_TableModel.hxx +++ b/tools/ViewControl/ViewControl_TableModel.hxx @@ -18,7 +18,6 @@ #include -#include #include #include @@ -40,7 +39,7 @@ class ViewControl_TableModel : public QAbstractTableModel public: //! Constructor - ViewControl_TableModel (QObject* theParent = 0) : myModelValues (0), myFilter (0) { (void)theParent; } + ViewControl_TableModel (QObject* theParent = 0) : myModelValues (0) { (void)theParent; } //! Destructor virtual ~ViewControl_TableModel() {} @@ -53,10 +52,6 @@ public: //! \return interface or NULL ViewControl_TableModelValues* GetModelValues() const { return myModelValues; } - //! Sets table values filter to rearrange values presentation - //! \param filter instance - void SetFilter (ViewControl_TableModelFilter* theFilter) { myFilter = theFilter; } - //! Emits the layoutChanged signal from outside of this class void EmitLayoutChanged() { emit layoutChanged(); } @@ -98,20 +93,8 @@ public: Qt::ItemFlags flags (const QModelIndex& theIndex) const { return myModelValues ? myModelValues->Flags (theIndex) : Qt::NoItemFlags; } - //! Returns source row and column values peforming conversion back from filter - //! \param theIndex a model index - //! \param theRow a model row - //! \param theColumn a model column - Standard_EXPORT void GetSourcePosition (const QModelIndex& theIndex, int& theRow, int& theColumn); - -protected: - //! Returns true if the filter is not NULL and active - //! \return true if active - Standard_Boolean isFilterActive() const { return myFilter && myFilter->IsActive(); } - private: ViewControl_TableModelValues* myModelValues; //! interface to table values - ViewControl_TableModelFilter* myFilter; //! filter of values }; #endif diff --git a/tools/ViewControl/ViewControl_TableModelFilter.hxx b/tools/ViewControl/ViewControl_TableModelFilter.hxx deleted file mode 100644 index 3e3adc044c..0000000000 --- a/tools/ViewControl/ViewControl_TableModelFilter.hxx +++ /dev/null @@ -1,76 +0,0 @@ -// 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 ViewControl_TableModelFilter_H -#define ViewControl_TableModelFilter_H - -#include - -#include - -//! \class ViewControl_TableModelFilter -//! \brief It provides separation of 1D container of values in 2D presentation depending on number of column value -class ViewControl_TableModelFilter -{ -public: - - //! Constructor - Standard_EXPORT ViewControl_TableModelFilter(const Standard_Integer theColumnCount = -1) - : myIsActive (Standard_True), myColumnCount (theColumnCount) {} - - //! Destructor - virtual ~ViewControl_TableModelFilter() {} - - //! Activate/Deactivate filter - //! \param theActive state is the filter to be active or not - virtual void SetActive (const Standard_Boolean theActive) { myIsActive = theActive; } - - //! Returns boolean state whether the filter is activated - //! \return true if active - virtual Standard_Boolean IsActive() const { return myIsActive; } - - //! Sets number of columns - //! \param theColumnCount a column count - void SetColumnCount (const int theColumnCount) { myColumnCount = theColumnCount; } - - //! Returns number of columns: parameter value - //! \param theSourceColumnCount number of columns in the source table - //! \return an integer value - Standard_EXPORT int ColumnCount (const int theSourceColumnCount) const; - - //! Returns number of rows: whole number of columns is divided to the current column value - //! \param theSourceColumnCount number of columns in the source table - //! \return an integer value - Standard_EXPORT int RowCount (const int theSourceColumnCount) const; - - //! Returns source row/column indices for the filtered model index - //! \param theIndex a model index - //! \param theRow [out] row number value - //! \param theColumn [out] column value - Standard_EXPORT void GetSourcePosition (const QModelIndex& theIndex, int& theRow, int& theColumn) const; - - //! Returns source row/column indices for the filtered model index - //! \param theSourceRow model row index - //! \param theSourceColumn model column index - //! \param theRow [out] row number value - //! \param theColumn [out] column value - Standard_EXPORT void GetSourcePosition (const int theSourceRow, const int theSourceColumn, int& theRow, int& theColumn) const; - -private: - Standard_Boolean myIsActive; //!< active state of the filter - Standard_Integer myColumnCount; //!< number of table columns -}; - -#endif diff --git a/tools/ViewControl/ViewControl_TableModelValues.cxx b/tools/ViewControl/ViewControl_TableModelValues.cxx index 8ac5e59e30..2017acc7eb 100644 --- a/tools/ViewControl/ViewControl_TableModelValues.cxx +++ b/tools/ViewControl/ViewControl_TableModelValues.cxx @@ -27,11 +27,24 @@ int ViewControl_TableModelValues::ColumnCount (const QModelIndex&) const { - Qt::Orientation anAdditionalOrientation = myOrientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical; - if (myHeaderValues[anAdditionalOrientation].size() > 0) - return myHeaderValues[anAdditionalOrientation].size(); + if (!GetProperties().IsNull()) + return GetProperties()->GetTableColumnCount(); - return myValues.size(); + return 0; +} + + +// ======================================================================= +// function : RowCount +// purpose : +// ======================================================================= + +int ViewControl_TableModelValues::RowCount (const QModelIndex&) const +{ + if (!GetProperties().IsNull()) + return GetProperties()->GetTableRowCount(); + + return 0; } // ======================================================================= @@ -41,8 +54,12 @@ int ViewControl_TableModelValues::ColumnCount (const QModelIndex&) const QVariant ViewControl_TableModelValues::Data (const int theRow, const int theColumn, int theRole) const { - if (theRole == Qt::DisplayRole) - return myValues.at ((int)getPosition (theRow, theColumn)); + if (!GetProperties().IsNull()) + { + QVariant aValue = GetProperties()->GetTableData (theRow, theColumn, theRole); + if (aValue.isValid()) + return aValue; + } if (theRole == Qt::TextAlignmentRole) // for multi-lines text, align it to the top return Qt::AlignTop; @@ -61,6 +78,19 @@ QVariant ViewControl_TableModelValues::Data (const int theRow, const int theColu return QVariant(); } +// ======================================================================= +// function : SetData +// purpose : +// ======================================================================= + +bool ViewControl_TableModelValues::SetData (const int theRow, const int theColumn, const QVariant& theValue, int) +{ + if (!GetProperties().IsNull()) + return GetProperties()->SetTableData (theRow, theColumn, theValue); + + return false; +} + // ======================================================================= // function : HeaderData // purpose : @@ -88,4 +118,4 @@ bool ViewControl_TableModelValues::isItalicHeader (const int theRow, const int t int aCell = anOrientation == Qt::Horizontal ? theColumn : theRow; return GetHeaderItem (anOrientation, aCell).IsItalic(); -} \ No newline at end of file +} diff --git a/tools/ViewControl/ViewControl_TableModelValues.hxx b/tools/ViewControl/ViewControl_TableModelValues.hxx index c0d8ac5c2d..63e6a32967 100644 --- a/tools/ViewControl/ViewControl_TableModelValues.hxx +++ b/tools/ViewControl/ViewControl_TableModelValues.hxx @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -40,21 +41,21 @@ public: //! Constructor Standard_EXPORT ViewControl_TableModelValues (const Qt::Orientation& theOrientation = Qt::Vertical) - : myUseTableProperties (false), myUseTableSeparateSize (true), myUseTablePropertiesXStep (false), - myUseTablePropertiesXStepValue (-1) { SetOrientation (theOrientation); } //! Destructor virtual ~ViewControl_TableModelValues() {} + //! Sets item table properties builder + void SetProperties (const Handle(TreeModel_ItemProperties)& theProperties) { myProperties = theProperties; } + + //! Returns item table properties builder + Handle(TreeModel_ItemProperties) GetProperties() const { return myProperties; } + //! Sets direction of the values applying, whether it should be placed by rows or by columns //! \param theOrientation if horizontal, the values are applyed by rows, otherwise by columns void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; } - //! Fills the model values. - //! \param theValues a container of table model values - void SetValues (const QVector& theValues) { myValues = theValues; } - //! Fills the model header values for orientation. //! \param theValues a container of header text values //! \param theOrientation an orientation of header @@ -94,34 +95,6 @@ public: return myDefaultSectionSize.contains (theOrientation); } - //! Stores whether the properties control of the table visible or not - //! \param theUseProperties boolean state - void SetUseTableProperties (const bool theUseProperties) { myUseTableProperties = theUseProperties; } - - //! Returns true if the properties control of the table visible or not - //! \return boolean value - bool UseTableProperties() const { return myUseTableProperties; } - - //! Stores whether the properties control of the table visible or not - //! \param theUseProperties boolean state - void SetUseTableSeparateSize (const bool theUseSize) - { myUseTableSeparateSize = theUseSize; } - - //! Returns true if the properties control of the table visible or not - //! \return boolean value - bool UseTableSeparateSize() const - { return myUseTableSeparateSize; } - - //! Stores whether the properties control of the table visible or not - //! \param theUseProperties boolean state - void SetUseTablePropertiesXStep (const bool theUseStep, const double theStep) - { myUseTablePropertiesXStep = theUseStep; myUseTablePropertiesXStepValue = theStep; } - - //! Returns true if the properties control of the table visible or not - //! \return boolean value - double UseTablePropertiesXStep(bool& theUseStep) const - { theUseStep = myUseTablePropertiesXStep; return myUseTablePropertiesXStepValue; } - //! Returns number of columns, size of header values //! \param theParent an index of the parent item //! \return an integer value @@ -130,8 +103,7 @@ public: //! 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 - virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const - { return ColumnCount (theParent) > 0 ? GetValuesCount() / ColumnCount (theParent) : 0; } + Standard_EXPORT virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const; //! Returns content of the model index for the given role, it is obtained from internal container of values //! It returns value only for DisplayRole. @@ -147,8 +119,7 @@ public: //! \param theRole a view role //! \return true if the value is changed Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue, - int theRole = Qt::DisplayRole) - { (void)theRow; (void)theColumn; (void)theValue; (void)theRole; return false; } + int theRole = Qt::DisplayRole); //! Returns content of the model index for the given role, it is obtainer from internal container of header values //! It returns value only for DisplayRole. @@ -164,28 +135,6 @@ public: virtual Qt::ItemFlags Flags (const QModelIndex& theIndex) const { return theIndex.isValid() ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags; } - //! Returns minimum and maximum values of the table content - //! \param theMinValue minimum - //! \param theMaxValue maximum - virtual void GetRangeValues (QString& theMinValue, QString& theMaxValue, const QModelIndexList& theSelected) const - { (void)theMinValue; (void)theMaxValue; (void)theSelected; } - - //! Returns additional info - virtual QString AdditionalInformation() const { return QString(); } - - //! 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 - virtual int GetValuesCount () const { return myValues.size(); } - - //! Returns source row/column indices for the filtered model index for the given role - //! \param theSourceRow model row index - //! \param theSourceColumn model column index - //! \param theRow [out] row number value - //! \param theColumn [out] column value - Standard_EXPORT virtual void GetSourcePosition (const int theSourceRow, const int theSourceColumn, int& theRow, int& theColumn) const - { theRow = theSourceRow; theColumn = theSourceColumn; } - //! Returns item delegate to provide cell editors. By default, it is empty //! \return delegate virtual QItemDelegate* GetItemDelegate() { return 0; } @@ -209,11 +158,6 @@ public: static QColor EditCellColor() { return QColor (Qt::darkBlue); } protected: - //! Finds position in internal vector of values using the table column/row count - //! \param theRow a row of a table cell - //! \param theColumn a column of a table cell - size_t getPosition (const int theRow, const int theColumn) const { return ColumnCount() * theRow + theColumn; } - //! Returns true if the header item is italic of the parameter index //! \param theRow a model index row //! \param theColumn a model index column @@ -226,11 +170,8 @@ protected: QMap > myHeaderValues; //!< table header values QMap myVisibleHeader; //! table header visibility QMap myDefaultSectionSize; //! table section default size - QVector myValues; //! cached container of table values - bool myUseTableProperties; //! state whether the table property control is visible - bool myUseTableSeparateSize; //! state whether table custom column size is possible - bool myUseTablePropertiesXStep; //! true if XStep value is used - double myUseTablePropertiesXStepValue; //! value to define OX step for 1D table, Z = 0 + + Handle(TreeModel_ItemProperties) myProperties; //!< item properties }; #endif diff --git a/tools/ViewControl/ViewControl_TableModelValuesDefault.cxx b/tools/ViewControl/ViewControl_TableModelValuesDefault.cxx new file mode 100644 index 0000000000..104bfbe5de --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModelValuesDefault.cxx @@ -0,0 +1,48 @@ +// 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 + +// ======================================================================= +// function : ColumnCount +// purpose : +// ======================================================================= + +int ViewControl_TableModelValuesDefault::ColumnCount (const QModelIndex&) const +{ + Qt::Orientation anAdditionalOrientation = myOrientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical; + if (myHeaderValues[anAdditionalOrientation].size() > 0) + return myHeaderValues[anAdditionalOrientation].size(); + + return myValues.size(); +} + +// ======================================================================= +// function : Data +// purpose : +// ======================================================================= + +QVariant ViewControl_TableModelValuesDefault::Data (const int theRow, const int theColumn, int theRole) const +{ + if (theRole == Qt::DisplayRole) + return myValues.at ((int)getPosition (theRow, theColumn)); + + return ViewControl_TableModelValues::Data (theRow, theColumn, theRole); +} diff --git a/tools/ViewControl/ViewControl_TableModelValuesDefault.hxx b/tools/ViewControl/ViewControl_TableModelValuesDefault.hxx new file mode 100644 index 0000000000..bda3b94d75 --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModelValuesDefault.hxx @@ -0,0 +1,92 @@ +// 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 ViewControl_TableModelValuesDefault_H +#define ViewControl_TableModelValuesDefault_H + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +class QItemDelegate; + +//! \class ViewControl_TableModelValuesDefault +//! \brief This is an interace for ViewControl_TableModel to give real values of the model +//! It should be filled or redefined. +class ViewControl_TableModelValuesDefault : public ViewControl_TableModelValues +{ +public: + + //! Constructor + Standard_EXPORT ViewControl_TableModelValuesDefault (const Qt::Orientation& theOrientation = Qt::Vertical) + : ViewControl_TableModelValues (theOrientation) {} + + //! Destructor + virtual ~ViewControl_TableModelValuesDefault() {} + + //! Fills the model values. + //! \param theValues a container of table model values + void SetValues (const QVector& theValues) { myValues = theValues; } + + //! Returns number of columns, size of header values + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int ColumnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE; + + //! 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 + virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { return ColumnCount (theParent) > 0 ? GetValuesCount() / ColumnCount (theParent) : 0; } + + //! 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 Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! 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 + virtual int GetValuesCount () const { return myValues.size(); } + +protected: + //! Finds position in internal vector of values using the table column/row count + //! \param theRow a row of a table cell + //! \param theColumn a column of a table cell + size_t getPosition (const int theRow, const int theColumn) const { return ColumnCount() * theRow + theColumn; } + + //! Returns true if the header item is italic of the parameter index + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param boolean value + bool isItalicHeader (const int theRow, const int theColumn) const; + +protected: + + QVector myValues; //! cached container of table values +}; + +#endif diff --git a/tools/ViewControl/ViewControl_TableProperty.cxx b/tools/ViewControl/ViewControl_TableProperty.cxx deleted file mode 100644 index e3c3a08c59..0000000000 --- a/tools/ViewControl/ViewControl_TableProperty.cxx +++ /dev/null @@ -1,224 +0,0 @@ -// 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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -const int DEFAULT_COLUMN_WIDTH = 60; - -// ======================================================================= -// function : Constructor -// purpose : -// ======================================================================= - -ViewControl_TableProperty::ViewControl_TableProperty (QWidget* theParent, ViewControl_Table* theTable) -: QObject (theParent), myTable (theTable), myIsActive (false) -{ - myFilter = new ViewControl_TableModelFilter(); - - myMainWidget = new QWidget (theParent); - QGridLayout* aMainLayout = new QGridLayout (myMainWidget); - - QWidget* aProperties = new QWidget (myMainWidget); - aMainLayout->addWidget (aProperties); - QHBoxLayout* aPropertiesLayout = new QHBoxLayout (aProperties); - aPropertiesLayout->setContentsMargins (0, 0, 0, 0); - - mySize = new QLabel ("", myMainWidget); - myDivideSize = new QLabel("Divide:", myMainWidget); - mySeparateSize = new QSpinBox (myMainWidget); - mySeparateSize->setRange (0, 100000); - myVisualizedSize = new QLabel ("", myMainWidget); - - aPropertiesLayout->addWidget (mySize); - aPropertiesLayout->addWidget (myDivideSize); - aPropertiesLayout->addWidget (mySeparateSize); - aPropertiesLayout->addWidget (myVisualizedSize); - - myXStepLabel = new QLabel ("XStep:"); - myXStep = new QDoubleSpinBox (myMainWidget); - myXStep->setRange(1.e-12, 1.e+7); - myXStep->setDecimals (8); - myXStep->setValue(1.); - - setXStepActive (false); - - connect (myXStep, SIGNAL(editingFinished()), this, SIGNAL (propertyChanged())); - - aPropertiesLayout->addWidget (myXStepLabel); - aPropertiesLayout->addWidget (myXStep); - - myInformationWidget = new QWidget (theParent); - QGridLayout* anInfoLayout = new QGridLayout (myInformationWidget); - - myModelInformation = new QPlainTextEdit (myInformationWidget); - myModelInformation->setVisible (false); - anInfoLayout->addWidget (myModelInformation, 2, 0, 1, 4); - - myMinValue = new QPushButton ("Min", myInformationWidget); - myMaxValue = new QPushButton ("Max", myInformationWidget); - myMinSelectedValue = new QPushButton ("Min of selected", myInformationWidget); - myMaxSelectedValue = new QPushButton ("Max of selected", myInformationWidget); - - anInfoLayout->addWidget (myMinValue, 3, 0); - anInfoLayout->addWidget (myMinSelectedValue, 3, 1); - anInfoLayout->addWidget (myMaxValue, 4, 0); - anInfoLayout->addWidget (myMaxSelectedValue, 4, 1); - - connect (mySeparateSize, SIGNAL (valueChanged (int)), - this, SLOT (onSeparateSizeChanged (int))); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= - -void ViewControl_TableProperty::Init() -{ - ViewControl_TableModel* aViewModel = dynamic_cast(myTable->GetTableView()->model()); - ViewControl_TableModelValues* aModelValues = aViewModel->GetModelValues(); - - bool aUseXStep; - double aXStep = aModelValues->UseTablePropertiesXStep (aUseXStep); - setXStepActive (aUseXStep, aXStep); - - QString aMinValue = QString::number (DBL_MIN), aMaxValue = QString::number (DBL_MAX); - aModelValues->GetRangeValues (aMinValue, aMaxValue, QModelIndexList()); - QString anInfo = aModelValues->AdditionalInformation(); - - bool aUseSeparateSize = aModelValues->UseTableSeparateSize(); - mySize->setVisible (aUseSeparateSize); - myDivideSize->setVisible (aUseSeparateSize); - mySeparateSize->setVisible (aUseSeparateSize); - myVisualizedSize->setVisible (aUseSeparateSize); - myFilter->SetActive (aUseSeparateSize); - if (aUseSeparateSize && mySeparateSize->value() != 0) - myFilter->SetColumnCount(mySeparateSize->value()); - - mySize->setText (QString("[ %1, %2 ]").arg (aViewModel->rowCount()).arg (aViewModel->columnCount())); - - myVisualizedSize->setText (mySize->text()); - myVisualizedSize->setToolTip (QString ("sqrt: (%1, %2)").arg (sqrt (aViewModel->rowCount())).arg (sqrt (aViewModel->columnCount()))); - myModelInformation->setVisible(!anInfo.isEmpty()); - if (!anInfo.isEmpty()) - myModelInformation->setPlainText (anInfo); - - myMinValue->setText (QString ("Min: ") + aMinValue); - myMaxValue->setText (QString ("Max: ") + aMaxValue); - myMinSelectedValue->setText (QString("Min of selected: ") + QString::number(0)); - myMaxSelectedValue->setText (QString("Max of selected: ") + QString::number(0)); -} - -// ======================================================================= -// function : SetActive -// purpose : -// ======================================================================= - -void ViewControl_TableProperty::SetActive (const bool theActive) -{ - GetControl()->setVisible (theActive); - GetInformationControl()->setVisible (theActive); - - ViewControl_TableModel* aModel = dynamic_cast (myTable->GetTableView()->model()); - aModel->SetFilter (theActive ? GetFilter() : 0); -} - -// ======================================================================= -// function : onSeparateSizeChanged -// purpose : -// ======================================================================= - -void ViewControl_TableProperty::onSeparateSizeChanged (int theValue) -{ - myFilter->SetColumnCount(theValue); - - myTable->GetTableView()->selectionModel()->clearSelection(); - - ViewControl_TableModel* aViewModel = dynamic_cast(myTable->GetTableView()->model()); - aViewModel->EmitLayoutChanged(); - - myVisualizedSize->setText (QString ("[ %1, %2 ]").arg (aViewModel->rowCount()).arg (aViewModel->columnCount())); -} - -// ======================================================================= -// function : onToleranceSizeChanged -// purpose : -// ======================================================================= - -void ViewControl_TableProperty::onToleranceSizeChanged (int theValue) -{ - (void)theValue; -} - -// ======================================================================= -// function : onSeparateSizeChanged -// purpose : -// ======================================================================= - -void ViewControl_TableProperty::UpdateOnTableSelectionChanged() -{ - QModelIndexList aSelected = myTable->GetTableView()->selectionModel()->selectedIndexes(); - if (aSelected.isEmpty()) - { - myMinSelectedValue->setText(QString("Min of selected:") + QString::number(0)); - myMaxSelectedValue->setText(QString("Max of selected:") + QString::number(0)); - return; - } - - ViewControl_TableModel* aViewModel = dynamic_cast(myTable->GetTableView()->model()); - ViewControl_TableModelValues* aModelValues = aViewModel->GetModelValues(); - - QString aMinValue = QString::number (DBL_MIN), aMaxValue = QString::number (DBL_MAX); - aModelValues->GetRangeValues (aMinValue, aMaxValue, aSelected); - - myMinSelectedValue->setText (QString ("Min of selected:") + aMinValue); - myMaxSelectedValue->setText (QString ("Max of selected:") + aMaxValue); -} - -// ======================================================================= -// function : createAction -// purpose : -// ======================================================================= -void ViewControl_TableProperty::setXStepActive (const bool theState, const double theValue) -{ - myXStepActive = theState; - - myXStepLabel->setVisible (myXStepActive); - myXStep->setVisible (myXStepActive); - - if (theValue > 0) - myXStep->setValue (theValue); -} diff --git a/tools/ViewControl/ViewControl_TableProperty.hxx b/tools/ViewControl/ViewControl_TableProperty.hxx deleted file mode 100644 index fbfa98c4b4..0000000000 --- a/tools/ViewControl/ViewControl_TableProperty.hxx +++ /dev/null @@ -1,141 +0,0 @@ -// 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 ViewControl_TableProperty_H -#define ViewControl_TableProperty_H - -#include -#include - -#ifdef _MSC_VER -#pragma warning(disable : 4127) // conditional expression is constant -#endif - -#include -#include -#include - -class ViewControl_Table; -class ViewControl_TableModelFilter; - -class QContextMenuEvent; -class QLabel; -class QItemSelection; -class QPlainTextEdit; -class QPushButton; -class QSpinBox; -class QWidget; - -//! \class ViewControl_TableProperty -//! \brief View to display table values with possibility to change table columns -//! if the table has 1D dimension and Horizontal orientation -class ViewControl_TableProperty : public QObject -{ - Q_OBJECT -public: - - //! Constructor - Standard_EXPORT ViewControl_TableProperty (QWidget* theParent, ViewControl_Table* theTable); - - //! Destructor - virtual ~ViewControl_TableProperty() Standard_OVERRIDE {} - - //! Fills table view and table size control by the model - Standard_EXPORT void Init(); - - //! Sets whether the properties pane is visible or not - //! \param theUseProperty boolean state - Standard_EXPORT void SetActive (const bool theActive); - - //! Returns main control - //! \return widget - QWidget* GetControl() const { return myMainWidget; } - - //! Returns information control - //! \return widget - QWidget* GetInformationControl() { return myInformationWidget; } - - //! Returns table values filter to apply separation size - //! \return filter instance - ViewControl_TableModelFilter* GetFilter() { return myFilter; } - - //! Returns X step or -1 if it is not used - //! \return double value - double GetXStep() const { return myXStepActive ? myXStep->value() : -1;}; - - //! Sets X step - //! \param theValue value - void SetXStep(const double theValue) const { myXStep->setValue (theValue); }; - - //! Returns divide valid - //! \return control value - int GetDivideSize() const { return mySeparateSize->value(); } - - //! Sets separate size value - //! \param theValue new value - void SetDivideSize (const int theValue) { mySeparateSize->setValue (theValue); } - -signals: - //! Signals about header cell is clicked - //! \param theEvent context menu event - void headerContextMenuRequsted (QContextMenuEvent* theEvent); - - //! Signals about the following properties are changed: XStep. - void propertyChanged(); - -protected slots: - //! Reacts to the spin box value change, it divides table model values to has given number of columns - //! \param theValue a new value of spin box - void onSeparateSizeChanged (int theValue); - - //! Reacts to the tolerance value change, it sets it into table model - //! \param theValue a new value of spin box - void onToleranceSizeChanged (int theValue); - -public: - //! Updates controls by selection change in table view - //! \param theSelected container of selected table cells - //! \param theDeselected container of selected table cells - void UpdateOnTableSelectionChanged(); - -private: - //! Changes visibility of XStep control, if visible, set parameter value - //! \param theState if true, the control is visible - //! \param theValue the current for the control - void setXStepActive (const bool theState, const double theValue = -1); - -private: - bool myIsActive; //!< state whether the control is visible and used - QWidget* myMainWidget; //!< parent of all controls - QLabel* mySize; //!< control to visualize initial values size - QLabel* myDivideSize; //!< size of division table values to rows - QSpinBox* mySeparateSize; //!< control to divide table by given size if thable has only 1 dimension - QLabel* myVisualizedSize; //!< control to visualize current table size - - bool myXStepActive; //!< state whether the XStep control is visible - QLabel* myXStepLabel; //!< label of X step - QDoubleSpinBox* myXStep; //!< control to enter X step - - QWidget* myInformationWidget; //!< parent of all controls - QPlainTextEdit* myModelInformation; //!< control to visualize current table size - QPushButton* myMinValue; //!< minimum table value - QPushButton* myMaxValue; //!< maximum table value - QPushButton* myMinSelectedValue; //!< minimum value of selected table cells - QPushButton* myMaxSelectedValue; //!< maximum value of selected table cells - - ViewControl_Table* myTable; //!< table control - ViewControl_TableModelFilter* myFilter; //!< table values filter to apply separation size -}; -#endif diff --git a/tools/ViewControl/ViewControl_Tools.cxx b/tools/ViewControl/ViewControl_Tools.cxx index 0b75af801e..dece84a49e 100644 --- a/tools/ViewControl/ViewControl_Tools.cxx +++ b/tools/ViewControl/ViewControl_Tools.cxx @@ -114,7 +114,7 @@ TCollection_AsciiString ViewControl_Tools::GetPointerInfo (const void* thePointe if (anInfoPtr.Value(aSymbolId) != '0') { anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); - anInfoPtr.Prepend("0x"); + anInfoPtr.Prepend(GetPointerPrefix()); return anInfoPtr; } } diff --git a/tools/ViewControl/ViewControl_Tools.hxx b/tools/ViewControl/ViewControl_Tools.hxx index 069c5e5abc..08c779e46f 100644 --- a/tools/ViewControl/ViewControl_Tools.hxx +++ b/tools/ViewControl/ViewControl_Tools.hxx @@ -42,6 +42,9 @@ class QWidget; class ViewControl_Tools { public: + //! Returns text of separation row in table + //! \return string value + static QString TableSeparator() { return "---------------------------"; } //! Creates an action with the given text connected to the slot //! \param theText an action text value @@ -61,6 +64,9 @@ public: //! \param theOrientation header orientation Standard_EXPORT static void SetDefaultHeaderSections (QTableView* theTableView, const Qt::Orientation theOrientation); + //! Returns default prefix added for each pointer info string + Standard_EXPORT static TCollection_AsciiString GetPointerPrefix() { return "0x"; } + //! 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 -- 2.39.5