]> OCCT Git - occt-copy.git/commitdiff
0030268: Inspectors - improvements in VInspector plugin
authorvlv <vadim.leontiev.ext@opencascade.com>
Wed, 24 Apr 2019 08:55:09 +0000 (11:55 +0300)
committervlv <vadim.leontiev.ext@opencascade.com>
Wed, 24 Apr 2019 08:59:03 +0000 (11:59 +0300)
- add dialog for gp_Pnt modification in ViewControls table
- VInspector - update tree model for new Parameters(pane/properties creator)

tests/v3d/glsl/clipping_selection_box [new file with mode: 0644]
tools/VInspector/VInspector_ItemV3dView.cxx
tools/VInspector/VInspector_Window.cxx
tools/ViewControl/FILES
tools/ViewControl/ViewControl_EditType.hxx
tools/ViewControl/ViewControl_TableDoubleVector.cxx [new file with mode: 0644]
tools/ViewControl/ViewControl_TableDoubleVector.hxx [new file with mode: 0644]
tools/ViewControl/ViewControl_TableItemDelegate.cxx

diff --git a/tests/v3d/glsl/clipping_selection_box b/tests/v3d/glsl/clipping_selection_box
new file mode 100644 (file)
index 0000000..c70d4be
--- /dev/null
@@ -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 \96plugins vinspector
+tinspector \96plugins messageview
+tinspector \96activate messageview
+activateReport
+tinspector -update
+
+# see messages from selection preparing in Inspector
+vselect 40 100 370 300
+
index beb64c9555bcbafa5668af7521130f880b8f2386..668ae51786831fe1174c51d32e926c594d25667e 100644 (file)
@@ -24,6 +24,7 @@
 #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>
@@ -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<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;
 }
 
index 8187ac7a17c30a935b0034591a210b3a2e74eca9..6f42d6ca777e7b0c1d06499cce0d61e147bb3f4f 100644 (file)
@@ -535,8 +535,13 @@ Handle(Graphic3d_TransformPers) VInspector_Window::GetSelectedTransformPers()
 // =======================================================================
 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())
   {
@@ -552,21 +557,20 @@ bool VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>
       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)
   {
@@ -576,6 +580,10 @@ bool VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>
     myCallBack->SetContext(aContext);
     myCallBack->SetHistoryModel(aHistoryModel);
   }
+
+  if (isModelUpdated)
+    UpdateTreeModel();
+
   return true;
 }
 
@@ -585,6 +593,9 @@ bool VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>
 // =======================================================================
 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);
index 7ccc28b096787442b673cf99001c2a60e8e6f588..ad85f4f68f6cea9e32ba182657125d5f53a54dc4 100644 (file)
@@ -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
index 2a095c378a2805f267f5f335ed53c177b5897ba1..92fba8084ede4f96e7bb0adf18759a4f52d5b25c 100644 (file)
@@ -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 (file)
index 0000000..31cb0ae
--- /dev/null
@@ -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 <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;
+}
+
diff --git a/tools/ViewControl/ViewControl_TableDoubleVector.hxx b/tools/ViewControl/ViewControl_TableDoubleVector.hxx
new file mode 100644 (file)
index 0000000..06cad58
--- /dev/null
@@ -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 <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
index 5696212d9d168c3b1b11f8b934fbee39d009257c..73f5e939a23294f2c32d39e70805ca669d85a0c2 100644 (file)
@@ -17,6 +17,7 @@
 #include <inspector/ViewControl_ColorSelector.hxx>
 #include <inspector/ViewControl_TableModelValues.hxx>
 #include <inspector/ViewControl_EditType.hxx>
+#include <inspector/ViewControl_TableDoubleVector.hxx>
 
 #include <Standard_WarningsDisable.hxx>
 #include <QFont>
@@ -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<QLineEdit*>(theEditor))->setText (theValue.toString()); break;
     case ViewControl_EditType_Spin: (qobject_cast<QSpinBox*>(theEditor))->setValue (theValue.toInt()); break;
     case ViewControl_EditType_DoAction: (qobject_cast<QPushButton*>(theEditor))->setText ("UnSelect"); break;
+    case ViewControl_EditType_DoubleVector: (qobject_cast<ViewControl_TableDoubleVector*>(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<QLineEdit*>(theEditor))->text();
     case ViewControl_EditType_Spin: return (qobject_cast<QSpinBox*>(theEditor))->value();
     case ViewControl_EditType_DoAction: return QVariant ("Clicked");
+    case ViewControl_EditType_DoubleVector: return (qobject_cast<ViewControl_TableDoubleVector*>(theEditor))->GetVector();
 
     default: return QVariant();
   }