From: vlv Date: Wed, 24 Apr 2019 08:55:09 +0000 (+0300) Subject: 0030268: Inspectors - improvements in VInspector plugin X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=07d3b289c68a97f1e0286a19ef5013529779c980;p=occt-copy.git 0030268: Inspectors - improvements in VInspector plugin - add dialog for gp_Pnt modification in ViewControls table - VInspector - update tree model for new Parameters(pane/properties creator) --- diff --git a/tests/v3d/glsl/clipping_selection_box b/tests/v3d/glsl/clipping_selection_box new file mode 100644 index 0000000000..c70d4be1d0 --- /dev/null +++ b/tests/v3d/glsl/clipping_selection_box @@ -0,0 +1,41 @@ +# creating three 3D objects +# cut view scene by clipping plane +# expecting two objects selected + +pload ALL +vinit View1 + +box b 10 10 10 +vdisplay b + +box b1 -5 0 0 2 2 2 +vdisplay b1 + +box b2 13 0 0 2 2 2 +vdisplay b2 + +vsetdispmode 1 + +vclipplane create pln +vclipplane set pln view Driver1/Viewer1/View1 +vclipplane change pln equation -1 0 0 5 + +vtop +vfit +vzoom 0.5 +vselect 40 100 370 300 + +# expected result is 2 objects, but clipping is not applyed for selection by box +vnbselected + +# check selected elements in Inspector +pload INSPECTOR +tinspector –plugins vinspector +tinspector –plugins messageview +tinspector –activate messageview +activateReport +tinspector -update + +# see messages from selection preparing in Inspector +vselect 40 100 370 300 + diff --git a/tools/VInspector/VInspector_ItemV3dView.cxx b/tools/VInspector/VInspector_ItemV3dView.cxx index beb64c9555..668ae51786 100644 --- a/tools/VInspector/VInspector_ItemV3dView.cxx +++ b/tools/VInspector/VInspector_ItemV3dView.cxx @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -130,8 +131,13 @@ int VInspector_ItemV3dView::GetTableRowCount() const // function : GetTableEditType // purpose : // ======================================================================= -ViewControl_EditType VInspector_ItemV3dView::GetTableEditType (const int, const int) const +ViewControl_EditType VInspector_ItemV3dView::GetTableEditType (const int theRow, const int) const { + switch (theRow) + { + case 2: return ViewControl_EditType_DoubleVector; + } + return ViewControl_EditType_None; } @@ -217,8 +223,36 @@ QVariant VInspector_ItemV3dView::GetTableData (const int theRow, const int theCo // function : SetTableData // purpose : // ======================================================================= -bool VInspector_ItemV3dView::SetTableData (const int, const int, const QVariant&) +bool VInspector_ItemV3dView::SetTableData (const int theRow, const int theColumn, const QVariant& theValue) { + Handle(V3d_View) aView = GetView(); + if (aView.IsNull()) + return false; + + if (theColumn == 0) + return false; + + switch (theRow) + { + case 2: + { + QString aValue = theValue.toString(); + Standard_Real aX, anY, aZ, aVx, aVy, aVz; + QList aValues = ViewControl_TableDoubleVector::GetListVector(aValue); + + if (aValues.size() == 3) + { + aX = aValues[0].toFloat(); + anY = aValues[1].toFloat(); + aZ = aValues[2].toFloat(); + + Standard_Real aTmpX, aTmpY, aTmpZ; + aView->Axis(aTmpX, aTmpY, aTmpZ, aVx, aVy, aVz); + + aView->SetAxis(aX, anY, aZ, aVx, aVy, aVz); + } + } + } return true; } diff --git a/tools/VInspector/VInspector_Window.cxx b/tools/VInspector/VInspector_Window.cxx index 8187ac7a17..6f42d6ca77 100644 --- a/tools/VInspector/VInspector_Window.cxx +++ b/tools/VInspector/VInspector_Window.cxx @@ -535,8 +535,13 @@ Handle(Graphic3d_TransformPers) VInspector_Window::GetSelectedTransformPers() // ======================================================================= bool VInspector_Window::Init (const NCollection_List& theParameters) { + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aViewModel) + return Standard_False; + Handle(AIS_InteractiveContext) aContext; Handle(VInspector_CallBack) aCallBack; + Standard_Boolean isModelUpdated = Standard_False; for (NCollection_List::Iterator aParamsIt (theParameters); aParamsIt.More(); aParamsIt.Next()) { @@ -552,21 +557,20 @@ bool VInspector_Window::Init (const NCollection_List Handle(ViewControl_PaneCreator) aPaneCreator = Handle(ViewControl_PaneCreator)::DownCast (anObject); if (!myPaneCreators.Contains (aPaneCreator)) myPaneCreators.Append (aPaneCreator); + isModelUpdated = Standard_True; } if (!Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject).IsNull()) { - Handle(TreeModel_ItemPropertiesCreator) aPropCreator = Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject); - VInspector_ViewModel* aViewModel = dynamic_cast(myTreeView->model()); - aViewModel->AddPropertiesCreator (aPropCreator); + Handle(TreeModel_ItemPropertiesCreator) aPropCreator = Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject); + VInspector_ViewModel* aViewModel = dynamic_cast(myTreeView->model()); + aViewModel->AddPropertiesCreator (aPropCreator); + isModelUpdated = Standard_True; } } - if (aContext.IsNull()) - return false; - VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); - if (aViewModel && aViewModel->GetContext() == aContext) - UpdateTreeModel(); + if (aViewModel->GetContext() != aContext) + SetContext(aContext); else - SetContext (aContext); + isModelUpdated = Standard_True; if (!aCallBack.IsNull() && aCallBack != myCallBack) { @@ -576,6 +580,10 @@ bool VInspector_Window::Init (const NCollection_List myCallBack->SetContext(aContext); myCallBack->SetHistoryModel(aHistoryModel); } + + if (isModelUpdated) + UpdateTreeModel(); + return true; } @@ -585,6 +593,9 @@ bool VInspector_Window::Init (const NCollection_List // ======================================================================= void VInspector_Window::SetContext (const Handle(AIS_InteractiveContext)& theContext) { + if (theContext.IsNull()) + return; + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); aViewModel->SetContext (theContext); myTreeView->setExpanded (aViewModel->index (0, 0), true); diff --git a/tools/ViewControl/FILES b/tools/ViewControl/FILES index 7ccc28b096..ad85f4f68f 100644 --- a/tools/ViewControl/FILES +++ b/tools/ViewControl/FILES @@ -12,6 +12,8 @@ ViewControl_PropertyView.cxx ViewControl_PropertyView.hxx ViewControl_Table.cxx ViewControl_Table.hxx +ViewControl_TableDoubleVector.cxx +ViewControl_TableDoubleVector.hxx ViewControl_TableItemDelegate.cxx ViewControl_TableItemDelegate.hxx ViewControl_TableModel.cxx diff --git a/tools/ViewControl/ViewControl_EditType.hxx b/tools/ViewControl/ViewControl_EditType.hxx index 2a095c378a..92fba8084e 100644 --- a/tools/ViewControl/ViewControl_EditType.hxx +++ b/tools/ViewControl/ViewControl_EditType.hxx @@ -26,7 +26,7 @@ enum ViewControl_EditType ViewControl_EditType_Double, //!< line edit widget used double validator ViewControl_EditType_Line, //!< line edit widget ViewControl_EditType_Spin, //!< spin box widget - ViewControl_EditType_DoubleVec3, //!< control to enter three double values + ViewControl_EditType_DoubleVector, //!< control to enter three double values ViewControl_EditType_DoAction //!< control to perform the row action }; diff --git a/tools/ViewControl/ViewControl_TableDoubleVector.cxx b/tools/ViewControl/ViewControl_TableDoubleVector.cxx new file mode 100644 index 0000000000..31cb0aea71 --- /dev/null +++ b/tools/ViewControl/ViewControl_TableDoubleVector.cxx @@ -0,0 +1,264 @@ +//----------------------------------------------------------------------------- +// Created on: 2019-03-28 +// Created by: Vadim LEONTIEV +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of commercial software by OPEN CASCADE SAS. +// +// This software is furnished in accordance with the terms and conditions +// of the contract and with the inclusion of this copyright notice. +// This software or any other copy thereof may not be provided or otherwise +// be made available to any third party. +// No ownership title to the software is transferred hereby. +// +// OPEN CASCADE SAS makes no representation or warranties with respect to the +// performance of this software, and specifically disclaims any responsibility +// for any damages, special or consequential, connected with its use. +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +//! Model for a table of parameters: Values: X, Y, Z +class ViewControl_ParametersModelVector : public ViewControl_TableModelValues +{ +public: + ViewControl_ParametersModelVector(ViewControl_TableDoubleVector* theDoubleVector) + : ViewControl_TableModelValues(), myDoubleVector(theDoubleVector) {} + + virtual ~ViewControl_ParametersModelVector() {} + + //! Inits model by the parameters vector + //! \param theVector model the vector + void SetVector(const QList& theVector) + { + if (myVector.isEmpty()) + { myVector.clear(); } + + for (int aNumberVector = 0; aNumberVector < theVector.size(); ++aNumberVector) + { + myVector.append(theVector[aNumberVector]); + } + } + + //! Returns current vector + //! \return vector value to string + QList GetVector() const { return myVector; } + + //! Returns current vector + //! \return vector value to QList + QList GetListFromString(const QString& theVector) const + { + QList aDoubleList; + + QStringList aList = theVector.split(QString(","), QString::SkipEmptyParts); + if (aList.isEmpty()) + return aDoubleList; + + for (int aNumberValue = 0; aNumberValue < aList.size(); ++aNumberValue) + { + aDoubleList.append(QVariant(aList[aNumberValue])); + } + + return aDoubleList; + } + + //! Returns item information(short) for display role. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant Data(const int theRow, const int theColumn, + int theRole = Qt::DisplayRole) const Standard_OVERRIDE + { + if (theRole != Qt::DisplayRole) + return QVariant(); + + bool isFirstColumn = theColumn == 0; + switch (theRow) + { + case 0: return isFirstColumn ? QVariant("X") : myVector[theRow]; + case 1: return isFirstColumn ? QVariant("Y") : myVector[theRow]; + case 2: return isFirstColumn ? QVariant("Z") : myVector[theRow]; + } + return QVariant(); + } + + //! Sets content of the model index for the given role, it is applyed to internal container of values + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return true if the value is changed + virtual bool SetData(const int theRow, const int theColumn, const QVariant& theValue, int) + { + if (theColumn != 1 || theRow < 0 || theRow > 2) + return false; + + switch (theRow) + { + case 0: myVector[theRow] = theValue; break; + case 1: myVector[theRow] = theValue; break; + case 2: myVector[theRow] = theValue; break; + } + + return true; + } + + //! Returns number of tree level line items = colums in table view + virtual int ColumnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 2; } + + //! Returns onlly one row in table view + virtual int RowCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 3; } + + //! Returns editable flag for DoubleVector + //! \return flags + Qt::ItemFlags Flags(const QModelIndex& theIndex) const + { + Qt::ItemFlags aFlags = ViewControl_TableModelValues::Flags(theIndex); + + if (theIndex.column() == 1 && theIndex.row() >= 0 && theIndex.row() <= 2) + aFlags = aFlags | Qt::ItemIsEditable; + + return aFlags; + } + + //! Returns type of edit control for the model index. By default, it is an empty control + //! \param theRow a model index row + //! \param theColumn a model index column + //! \return edit type + virtual ViewControl_EditType GetEditType(const int theRow, const int theColumn) const + { + if (theColumn == 1 && theRow >= 0 && theRow <= 2) + return ViewControl_EditType_Double; + + return ViewControl_EditType_None; + } + +private: + QList myVector; + ViewControl_TableDoubleVector* myDoubleVector; +}; + + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= + +ViewControl_TableDoubleVector::ViewControl_TableDoubleVector(QWidget* theParent) +: QDialog(theParent) +{ + QGridLayout* aLayout = new QGridLayout(this); + aLayout->setContentsMargins(0, 0, 0, 0); + + myParameters = new QTableView(this); + + ViewControl_TableModel* aTableModel = new ViewControl_TableModel(myParameters); + aTableModel->SetModelValues(new ViewControl_ParametersModelVector(this)); + myParameters->setModel(aTableModel); + + ViewControl_TableItemDelegate* anItemDelegate = new ViewControl_TableItemDelegate(); + anItemDelegate->SetModelValues(aTableModel->GetModelValues()); + myParameters->setItemDelegate(anItemDelegate); + + myParameters->verticalHeader()->setDefaultSectionSize(myParameters->verticalHeader()->minimumSectionSize()); + myParameters->verticalHeader()->setVisible(false); + myParameters->horizontalHeader()->setVisible(false); + myParameters->setMinimumHeight(myParameters->verticalHeader()->minimumSectionSize() * aTableModel->rowCount() + + TreeModel_Tools::HeaderSectionMargin()); + myParameters->setMinimumWidth(myParameters->horizontalHeader()->defaultSectionSize() * aTableModel->columnCount() + + TreeModel_Tools::HeaderSectionMargin()); + + QItemSelectionModel* aSelectionModel = new QItemSelectionModel(myParameters->model()); + myParameters->setSelectionMode(QAbstractItemView::SingleSelection); + myParameters->setSelectionModel(aSelectionModel); + + aLayout->addWidget(myParameters, 0, 0); + + myDialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + connect(myDialogButtons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(myDialogButtons, &QDialogButtonBox::rejected, this, &QDialog::reject); + + aLayout->addWidget(myDialogButtons, 1, 0, 1, 2); +} + +// ======================================================================= +// function : SetVectorValue +// purpose : +// ======================================================================= + +void ViewControl_TableDoubleVector::SetVectorValue(const QString& theVector) +{ + QList aVector = GetListVector(theVector); + // parameters model + ViewControl_TableModel* aTableModel = dynamic_cast (myParameters->model()); + ViewControl_ParametersModelVector* aParametersModel = dynamic_cast (aTableModel->GetModelValues()); + aParametersModel->SetVector(aVector); +} + +// ======================================================================= +// function : GetListVector +// purpose : +// ======================================================================= + +QList ViewControl_TableDoubleVector::GetListVector(const QString& theVector) +{ + QList aDoubleList; + + QStringList aList = theVector.split(ViewControl_TableDoubleVector::DoubleSeparator(), QString::SkipEmptyParts); + + if (aList.isEmpty()) + return aDoubleList; + + for (int aNumberValue = 0; aNumberValue < aList.size(); ++aNumberValue) + { + aDoubleList.append(QVariant(aList[aNumberValue])); + } + + return aDoubleList; +} + +// ======================================================================= +// function : GetVector +// purpose : +// ======================================================================= + +QString ViewControl_TableDoubleVector::GetVector() const +{ + ViewControl_TableModel* aTableModel = dynamic_cast (myParameters->model()); + ViewControl_ParametersModelVector* aParametersModel = dynamic_cast (aTableModel->GetModelValues()); + + return VectorToString(aParametersModel->GetVector()); +} + +// ======================================================================= +// function : VectorToString +// purpose : +// ======================================================================= + +QString ViewControl_TableDoubleVector::VectorToString(const QList& theVector) const +{ + QString aVectorToString; + + for (int aNumberValue = 0; aNumberValue < theVector.size(); ++aNumberValue) + { + aVectorToString += theVector[aNumberValue].toString() + DoubleSeparator(); + } + aVectorToString.remove(aVectorToString.length() - 1, 1); + + return aVectorToString; +} + diff --git a/tools/ViewControl/ViewControl_TableDoubleVector.hxx b/tools/ViewControl/ViewControl_TableDoubleVector.hxx new file mode 100644 index 0000000000..06cad5806d --- /dev/null +++ b/tools/ViewControl/ViewControl_TableDoubleVector.hxx @@ -0,0 +1,76 @@ +//----------------------------------------------------------------------------- +// Created on: 2019-03-28 +// Created by: Vadim LEONTIEV +// Copyright (c) 2019 OPEN CASCADE SAS +// +// This file is part of commercial software by OPEN CASCADE SAS. +// +// This software is furnished in accordance with the terms and conditions +// of the contract and with the inclusion of this copyright notice. +// This software or any other copy thereof may not be provided or otherwise +// be made available to any third party. +// No ownership title to the software is transferred hereby. +// +// OPEN CASCADE SAS makes no representation or warranties with respect to the +// performance of this software, and specifically disclaims any responsibility +// for any damages, special or consequential, connected with its use. +//----------------------------------------------------------------------------- + +#ifndef ViewControl_TableDoubleVector_H +#define ViewControl_TableDoubleVector_H + +#include +#include + +#include +#include +#include +#include +#include +#include + +class QDialogButtonBox; +class QTableView; + +//! \class ViewControl_PointCoordinates +//! \dialog of change the point coordinates +class VIEWCONTROL_EXPORT ViewControl_TableDoubleVector : public QDialog +{ + Q_OBJECT +public: + + //! Constructor + ViewControl_TableDoubleVector(QWidget* theParent); + + //! Destructor + virtual ~ViewControl_TableDoubleVector() Standard_OVERRIDE{} + + //! Inits control by the vector value + //! \param theVector text vector value + void SetVectorValue(const QString& theVector); + + //! Returns vector value + //! \return QList vector value + static QList ViewControl_TableDoubleVector::GetListVector(const QString& theVector); + + //! Returns vector value + //! \return text vector value + QString GetVector() const; + + //! Converts vector to string value in form + //! \param theVector vector value + //! \return text value + QString VectorToString(const QList& theVector) const; + +private: + //! Returns symbol used as a separtor of vector components in string conversion + //! \return symbol value + static QString DoubleSeparator() { return ","; } + +private: + QTableView* myParameters; //! current vector parameters + QDialogButtonBox* myDialogButtons; //! OK/Cancel buttons + +}; + +#endif // ViewControl_TableDoubleVector_H diff --git a/tools/ViewControl/ViewControl_TableItemDelegate.cxx b/tools/ViewControl/ViewControl_TableItemDelegate.cxx index 5696212d9d..73f5e939a2 100644 --- a/tools/ViewControl/ViewControl_TableItemDelegate.cxx +++ b/tools/ViewControl/ViewControl_TableItemDelegate.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,7 @@ QWidget* ViewControl_TableItemDelegate::createEditorControl (QWidget* theParent, return aSpinBox; } case ViewControl_EditType_DoAction: return new QPushButton (theParent); + case ViewControl_EditType_DoubleVector: return new ViewControl_TableDoubleVector(theParent); default: return 0; } @@ -185,6 +187,7 @@ void ViewControl_TableItemDelegate::setEditorValue (QWidget* theEditor, const Vi case ViewControl_EditType_Line: (qobject_cast(theEditor))->setText (theValue.toString()); break; case ViewControl_EditType_Spin: (qobject_cast(theEditor))->setValue (theValue.toInt()); break; case ViewControl_EditType_DoAction: (qobject_cast(theEditor))->setText ("UnSelect"); break; + case ViewControl_EditType_DoubleVector: (qobject_cast(theEditor))->SetVectorValue(theValue.toString()); break; default: break; } @@ -207,6 +210,7 @@ QVariant ViewControl_TableItemDelegate::getEditorValue (QWidget* theEditor, cons case ViewControl_EditType_Line: return (qobject_cast(theEditor))->text(); case ViewControl_EditType_Spin: return (qobject_cast(theEditor))->value(); case ViewControl_EditType_DoAction: return QVariant ("Clicked"); + case ViewControl_EditType_DoubleVector: return (qobject_cast(theEditor))->GetVector(); default: return QVariant(); }