Skip to content

Commit

Permalink
add qt widget specialization for CRSC
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy committed Nov 12, 2024
1 parent 0abfcab commit 8f6c208
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Sofa/GUI/Qt/src/sofa/gui/qt/SimpleDataWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ Creator<DataWidgetFactory, SimpleDataWidget< Mat<6,6,double> > > DWClass_Mat66d(
Creator<DataWidgetFactory, SimpleDataWidget< sofa::core::objectmodel::TagSet > > DWClass_TagSet("default",true);


Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<1,float>> > > DWClass_CRSCVec1f("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<2,float>> > > DWClass_CRSCVec2f("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<3,float>> > > DWClass_CRSCVec3f("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<6,float>> > > DWClass_CRSCVec6f("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<1,double>> > > DWClass_CRSCVec1d("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<2,double>> > > DWClass_CRSCVec2d("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<3,double>> > > DWClass_CRSCVec3d("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<6,double>> > > DWClass_CRSCVec6d("default",true);

////////////////////////////////////////////////////////////////
/// OptionsGroup support
////////////////////////////////////////////////////////////////
Expand Down
40 changes: 40 additions & 0 deletions Sofa/GUI/Qt/src/sofa/gui/qt/SimpleDataWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//#include <sofa/defaulttype/RigidTypes.h>
#include <sofa/type/fixed_array.h>
#include <sofa/core/topology/Topology.h>
#include <sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h>
#include "WDoubleLineEdit.h"
#include <climits>

Expand Down Expand Up @@ -932,6 +933,45 @@ template<sofa::Size L, sofa::Size C, class T>
class data_widget_container < sofa::type::Mat<L, C, T> > : public fixed_grid_data_widget_container < sofa::type::Mat<L, C, T> >
{};

////////////////////////////////////////////////////////////////
/// sofa::linearalgebra::CompressedRowSparseMatrixConstraint support
////////////////////////////////////////////////////////////////

template<typename TBlock>
class data_widget_trait <sofa::linearalgebra::CompressedRowSparseMatrixConstraint<TBlock>>
{
public:
typedef sofa::linearalgebra::CompressedRowSparseMatrixConstraint<TBlock> data_type;
typedef QLineEdit Widget;
static Widget* create(QWidget* parent, const data_type& /*d*/)
{
Widget* w = new Widget(parent);
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
return w;
}
static void readFromData(Widget* w, const data_type& d)
{
std::ostringstream oss;
d.prettyPrint(oss);
w->setText(QString(oss.str().c_str()));
}
static void writeToData(Widget* /* w */, const data_type& /* d */)
{
// not supported by this type
// TODO: CompressedRowSparseMatrixConstraint needs a parser for its pretty output
}
static void setReadOnly(Widget* w, bool readOnly)
{
w->setEnabled(!readOnly);
w->setReadOnly(readOnly);
}
static void connectChanged(Widget* w, DataWidget* datawidget)
{
datawidget->connect(w, SIGNAL( textChanged(const QString&) ), datawidget, SLOT(setWidgetDirty()) );
}

};

////////////////////////////////////////////////////////////////
/// OptionsGroup support
////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress
}

/// write into output stream (default is standard output)
void prettyPrint(std::ostream& out = std::cout)
void prettyPrint(std::ostream& out = std::cout) const
{
for (RowConstIterator rowIt = this->begin(); rowIt != this->end(); ++rowIt)
{
Expand Down

0 comments on commit 8f6c208

Please sign in to comment.