#include <V3d_ListOfLight.hxx>
#include <inspector/ViewControl_Tools.hxx>
+#include <inspector/ViewControl_TableDoubleVector.hxx>
#include <inspector/VInspector_ItemAspectWindow.hxx>
#include <inspector/VInspector_ItemContext.hxx>
#include <inspector/VInspector_ItemGraphic3dCamera.hxx>
// 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;
}
// 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<QVariant> 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;
}
// =======================================================================
bool VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>& theParameters)
{
+ VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
+ if (!aViewModel)
+ return Standard_False;
+
Handle(AIS_InteractiveContext) aContext;
Handle(VInspector_CallBack) aCallBack;
+ Standard_Boolean isModelUpdated = Standard_False;
for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt (theParameters); aParamsIt.More(); aParamsIt.Next())
{
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<VInspector_ViewModel*>(myTreeView->model());
- aViewModel->AddPropertiesCreator (aPropCreator);
+ Handle(TreeModel_ItemPropertiesCreator) aPropCreator = Handle(TreeModel_ItemPropertiesCreator)::DownCast (anObject);
+ VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*>(myTreeView->model());
+ aViewModel->AddPropertiesCreator (aPropCreator);
+ isModelUpdated = Standard_True;
}
}
- if (aContext.IsNull())
- return false;
- VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (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)
{
myCallBack->SetContext(aContext);
myCallBack->SetHistoryModel(aHistoryModel);
}
+
+ if (isModelUpdated)
+ UpdateTreeModel();
+
return true;
}
// =======================================================================
void VInspector_Window::SetContext (const Handle(AIS_InteractiveContext)& theContext)
{
+ if (theContext.IsNull())
+ return;
+
VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
aViewModel->SetContext (theContext);
myTreeView->setExpanded (aViewModel->index (0, 0), true);
--- /dev/null
+//-----------------------------------------------------------------------------
+// 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 <inspector/ViewControl_TableDoubleVector.hxx>
+#include <inspector/ViewControl_TableItemDelegate.hxx>
+#include <inspector/ViewControl_TableModel.hxx>
+#include <inspector/ViewControl_TableModelValues.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QDialogButtonBox>
+#include <QHeaderView>
+#include <QGridLayout>
+#include <QItemSelectionModel>
+#include <QTableView>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+//! 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<QVariant>& 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<QVariant> GetVector() const { return myVector; }
+
+ //! Returns current vector
+ //! \return vector value to QList
+ QList<QVariant> GetListFromString(const QString& theVector) const
+ {
+ QList<QVariant> 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<QVariant> 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<QVariant> aVector = GetListVector(theVector);
+ // parameters model
+ ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*> (myParameters->model());
+ ViewControl_ParametersModelVector* aParametersModel = dynamic_cast<ViewControl_ParametersModelVector*> (aTableModel->GetModelValues());
+ aParametersModel->SetVector(aVector);
+}
+
+// =======================================================================
+// function : GetListVector
+// purpose :
+// =======================================================================
+
+QList<QVariant> ViewControl_TableDoubleVector::GetListVector(const QString& theVector)
+{
+ QList<QVariant> 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<ViewControl_TableModel*> (myParameters->model());
+ ViewControl_ParametersModelVector* aParametersModel = dynamic_cast<ViewControl_ParametersModelVector*> (aTableModel->GetModelValues());
+
+ return VectorToString(aParametersModel->GetVector());
+}
+
+// =======================================================================
+// function : VectorToString
+// purpose :
+// =======================================================================
+
+QString ViewControl_TableDoubleVector::VectorToString(const QList<QVariant>& 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;
+}
+
--- /dev/null
+//-----------------------------------------------------------------------------
+// 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 <inspector/ViewControl.hxx>
+#include <inspector/ViewControl_Tools.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <Standard_Macro.hxx>
+#include <QDialog>
+#include <QString>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+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<QVariant> vector value
+ static QList<QVariant> 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<QVariant>& 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