1) CurveCreator_NewSection.h is replaced with CurveCreator_NewSectionDlg.h in Makefile.am

2) Some files are converted to UNIX format
3) CURVECREATOR_EXPORT macro is added to definiton of CurveCreator_Widget class (required for compilation on Windows)
This commit is contained in:
ouv 2013-08-21 07:55:34 +00:00
parent 2c4464497c
commit 6def90fa98
9 changed files with 1602 additions and 1600 deletions

View File

@ -1,161 +1,161 @@
#include "CurveCreator_NewPointDlg.h" #include "CurveCreator_NewPointDlg.h"
#include <QGridLayout> #include <QGridLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QDoubleValidator> #include <QDoubleValidator>
#include <QRegExpValidator> #include <QRegExpValidator>
#include <QAbstractButton> #include <QAbstractButton>
#include <QPushButton> #include <QPushButton>
#include <QLocale> #include <QLocale>
CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) : CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) :
QDialog(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false) QDialog(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false)
{ {
QGridLayout* aCoordLay = new QGridLayout(); QGridLayout* aCoordLay = new QGridLayout();
QString aTitle = QString(tr("ADD_NEW_POINT")); QString aTitle = QString(tr("ADD_NEW_POINT"));
setWindowTitle(aTitle); setWindowTitle(aTitle);
QLabel* aLbl = new QLabel( tr("X_COORD"), this); QLabel* aLbl = new QLabel( tr("X_COORD"), this);
myX = new QDoubleSpinBox(this); myX = new QDoubleSpinBox(this);
aCoordLay->addWidget(aLbl, 0, 0); aCoordLay->addWidget(aLbl, 0, 0);
aCoordLay->addWidget(myX, 0, 1 ); aCoordLay->addWidget(myX, 0, 1 );
aLbl = new QLabel( tr("Y_COORD"), this); aLbl = new QLabel( tr("Y_COORD"), this);
myY = new QDoubleSpinBox(this); myY = new QDoubleSpinBox(this);
aCoordLay->addWidget(aLbl, 1, 0 ); aCoordLay->addWidget(aLbl, 1, 0 );
aCoordLay->addWidget(myY, 1, 1 ); aCoordLay->addWidget(myY, 1, 1 );
myZLabel = new QLabel( tr("Z_COORD"), this); myZLabel = new QLabel( tr("Z_COORD"), this);
myZ = new QDoubleSpinBox(this); myZ = new QDoubleSpinBox(this);
aCoordLay->addWidget(myZLabel, 2,0 ); aCoordLay->addWidget(myZLabel, 2,0 );
aCoordLay->addWidget(myZ, 2,1 ); aCoordLay->addWidget(myZ, 2,1 );
if( theDim != CurveCreator::Dim3d ){ if( theDim != CurveCreator::Dim3d ){
myZ->hide(); myZ->hide();
myZLabel->hide(); myZLabel->hide();
} }
myBtnBox = new QDialogButtonBox(this); myBtnBox = new QDialogButtonBox(this);
myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole ); myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole );
myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole ); myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole );
myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole ); myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole );
connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept())); connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject())); connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) )); connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) ));
QVBoxLayout* aMainLay = new QVBoxLayout(); QVBoxLayout* aMainLay = new QVBoxLayout();
aMainLay->addLayout(aCoordLay); aMainLay->addLayout(aCoordLay);
aMainLay->addWidget(myBtnBox); aMainLay->addWidget(myBtnBox);
setLayout(aMainLay); setLayout(aMainLay);
clear(); clear();
updateTitle(); updateTitle();
} }
void CurveCreator_NewPointDlg::setSectionName( const QString& theName ) void CurveCreator_NewPointDlg::setSectionName( const QString& theName )
{ {
mySectionName = theName; mySectionName = theName;
updateTitle(); updateTitle();
} }
void CurveCreator_NewPointDlg::setEditMode( bool isEdit ) void CurveCreator_NewPointDlg::setEditMode( bool isEdit )
{ {
myIsEdit = isEdit; myIsEdit = isEdit;
if( myIsEdit ){ if( myIsEdit ){
myContBtn->hide(); myContBtn->hide();
myAddBtn->setText(tr("OK")); myAddBtn->setText(tr("OK"));
} }
else{ else{
myContBtn->show(); myContBtn->show();
myAddBtn->setText(tr("ADD_BTN")); myAddBtn->setText(tr("ADD_BTN"));
} }
updateTitle(); updateTitle();
} }
void CurveCreator_NewPointDlg::updateTitle() void CurveCreator_NewPointDlg::updateTitle()
{ {
QString aTitle; QString aTitle;
if( !myIsEdit ){ if( !myIsEdit ){
if( mySectionName.isEmpty() ){ if( mySectionName.isEmpty() ){
aTitle = tr("ADD_NEW_POINT"); aTitle = tr("ADD_NEW_POINT");
} }
else{ else{
aTitle = QString(tr("ADD_NEW_POINT_TO_%1")).arg(mySectionName); aTitle = QString(tr("ADD_NEW_POINT_TO_%1")).arg(mySectionName);
} }
} }
else{ else{
aTitle = tr("SET_POINT_COORDINATES"); aTitle = tr("SET_POINT_COORDINATES");
} }
setWindowTitle(aTitle); setWindowTitle(aTitle);
} }
CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const
{ {
CurveCreator::Coordinates aCoords; CurveCreator::Coordinates aCoords;
double anX = myX->value(); double anX = myX->value();
aCoords.push_back(anX); aCoords.push_back(anX);
double anY = myY->value(); double anY = myY->value();
aCoords.push_back(anY); aCoords.push_back(anY);
if( myZ->isVisible() ){ if( myZ->isVisible() ){
double aZ = myZ->value(); double aZ = myZ->value();
aCoords.push_back(aZ); aCoords.push_back(aZ);
} }
return aCoords; return aCoords;
} }
void CurveCreator_NewPointDlg::onBtnClicked(QAbstractButton* theBtn ) void CurveCreator_NewPointDlg::onBtnClicked(QAbstractButton* theBtn )
{ {
if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){ if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){
emit addPoint(); emit addPoint();
} }
} }
void CurveCreator_NewPointDlg::clear() void CurveCreator_NewPointDlg::clear()
{ {
initSpinBox(myX); initSpinBox(myX);
initSpinBox(myY); initSpinBox(myY);
initSpinBox(myZ); initSpinBox(myZ);
} }
void CurveCreator_NewPointDlg::setDimension(CurveCreator::Dimension theDim) void CurveCreator_NewPointDlg::setDimension(CurveCreator::Dimension theDim)
{ {
if( theDim == CurveCreator::Dim2d ){ if( theDim == CurveCreator::Dim2d ){
myZ->hide(); myZ->hide();
myZLabel->hide(); myZLabel->hide();
} }
else{ else{
myZ->show(); myZ->show();
myZLabel->show(); myZLabel->show();
} }
} }
void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords ) void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords )
{ {
double anX = theCoords[0]; double anX = theCoords[0];
myX->setValue(anX); myX->setValue(anX);
double anY = theCoords[1]; double anY = theCoords[1];
myY->setValue(anY); myY->setValue(anY);
if( theCoords.size() == 3 ){ if( theCoords.size() == 3 ){
double aZ = theCoords[2]; double aZ = theCoords[2];
myZ->setValue(aZ); myZ->setValue(aZ);
} }
} }
//======================================================================= //=======================================================================
// function: initSpinBox // function: initSpinBox
// purpose: // purpose:
//======================================================================= //=======================================================================
void CurveCreator_NewPointDlg::initSpinBox(QDoubleSpinBox *theSpinBox) void CurveCreator_NewPointDlg::initSpinBox(QDoubleSpinBox *theSpinBox)
{ {
const double aCoordMin = -1.e+15; const double aCoordMin = -1.e+15;
const double aCoordMax = 1.e+15; const double aCoordMax = 1.e+15;
const double aStep = 10; const double aStep = 10;
const int aPrecision = 6; const int aPrecision = 6;
theSpinBox->setDecimals( qAbs( aPrecision ) ); theSpinBox->setDecimals( qAbs( aPrecision ) );
theSpinBox->setRange(aCoordMin, aCoordMax); theSpinBox->setRange(aCoordMin, aCoordMax);
theSpinBox->setSingleStep(aStep); theSpinBox->setSingleStep(aStep);
theSpinBox->setValue(0.0); theSpinBox->setValue(0.0);
} }

View File

@ -1,46 +1,46 @@
#ifndef CURVECREATOR_NEWPOINTDLG_H #ifndef CURVECREATOR_NEWPOINTDLG_H
#define CURVECREATOR_NEWPOINTDLG_H #define CURVECREATOR_NEWPOINTDLG_H
#include "CurveCreator.hxx" #include "CurveCreator.hxx"
#include <QDialog> #include <QDialog>
class QDoubleSpinBox; class QDoubleSpinBox;
class QDialogButtonBox; class QDialogButtonBox;
class QAbstractButton; class QAbstractButton;
class QPushButton; class QPushButton;
class QLabel; class QLabel;
class CurveCreator_NewPointDlg : public QDialog class CurveCreator_NewPointDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent = 0); explicit CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent = 0);
CurveCreator::Coordinates getCoordinates() const; CurveCreator::Coordinates getCoordinates() const;
void clear(); void clear();
void setSectionName( const QString& theName ); void setSectionName( const QString& theName );
void setEditMode( bool isEdit ); void setEditMode( bool isEdit );
void setCoordinates( const CurveCreator::Coordinates& theCoords ); void setCoordinates( const CurveCreator::Coordinates& theCoords );
void setDimension(CurveCreator::Dimension theDim); void setDimension(CurveCreator::Dimension theDim);
signals: signals:
void addPoint(); void addPoint();
public slots: public slots:
protected slots: protected slots:
void onBtnClicked(QAbstractButton* theBtn ); void onBtnClicked(QAbstractButton* theBtn );
protected: protected:
void updateTitle(); void updateTitle();
void initSpinBox(QDoubleSpinBox *theSpinBox); void initSpinBox(QDoubleSpinBox *theSpinBox);
private: private:
QDialogButtonBox* myBtnBox; QDialogButtonBox* myBtnBox;
CurveCreator::Dimension myDim; CurveCreator::Dimension myDim;
QDoubleSpinBox* myX; QDoubleSpinBox* myX;
QDoubleSpinBox* myY; QDoubleSpinBox* myY;
QDoubleSpinBox* myZ; QDoubleSpinBox* myZ;
QLabel* myZLabel; QLabel* myZLabel;
QPushButton* myContBtn; QPushButton* myContBtn;
QPushButton* myAddBtn; QPushButton* myAddBtn;
bool myIsEdit; bool myIsEdit;
QString mySectionName; QString mySectionName;
}; };
#endif // CURVECREATOR_NEWPOINTDLG_H #endif // CURVECREATOR_NEWPOINTDLG_H

View File

@ -1,129 +1,129 @@
#include "CurveCreator_NewSectionDlg.h" #include "CurveCreator_NewSectionDlg.h"
#include "CurveCreator_Curve.hxx" #include "CurveCreator_Curve.hxx"
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QComboBox> #include <QComboBox>
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QPushButton> #include <QPushButton>
CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) : CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) :
QDialog(parent) QDialog(parent)
{ {
std::string aNameStr; std::string aNameStr;
QGridLayout* aLay = new QGridLayout(); QGridLayout* aLay = new QGridLayout();
QLabel* aLbl = new QLabel(tr("NAME"), this); QLabel* aLbl = new QLabel(tr("NAME"), this);
myName = new QLineEdit(this); myName = new QLineEdit(this);
aLay->addWidget(aLbl, 0, 0); aLay->addWidget(aLbl, 0, 0);
aLay->addWidget(myName, 0 , 1); aLay->addWidget(myName, 0 , 1);
aLbl = new QLabel(tr("LINE_TYPE")); aLbl = new QLabel(tr("LINE_TYPE"));
myLineType = new QComboBox(this); myLineType = new QComboBox(this);
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
// QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE")); // QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
// QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE")); // QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE")); myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE"));
myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE")); myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE"));
myLineType->setCurrentIndex(0); myLineType->setCurrentIndex(0);
aLay->addWidget(aLbl, 1, 0); aLay->addWidget(aLbl, 1, 0);
aLay->addWidget(myLineType, 1 , 1); aLay->addWidget(myLineType, 1 , 1);
aLbl = new QLabel(tr("LINE_CLOSED")); aLbl = new QLabel(tr("LINE_CLOSED"));
myIsClosed = new QCheckBox(this); myIsClosed = new QCheckBox(this);
aLay->addWidget(aLbl, 2, 0); aLay->addWidget(aLbl, 2, 0);
aLay->addWidget(myIsClosed, 2, 1); aLay->addWidget(myIsClosed, 2, 1);
myBtnBox = new QDialogButtonBox(this); myBtnBox = new QDialogButtonBox(this);
myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole ); myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole );
myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole ); myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole );
myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole ); myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole );
connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept())); connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject())); connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) )); connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) ));
QVBoxLayout* aMainLay = new QVBoxLayout(); QVBoxLayout* aMainLay = new QVBoxLayout();
aMainLay->addLayout(aLay); aMainLay->addLayout(aLay);
aMainLay->addWidget(myBtnBox); aMainLay->addWidget(myBtnBox);
setLayout(aMainLay); setLayout(aMainLay);
} }
void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType ) void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType )
{ {
myName->setText(theName); myName->setText(theName);
myIsClosed->setChecked(isClosed); myIsClosed->setChecked(isClosed);
if( theType == CurveCreator::Polyline ) if( theType == CurveCreator::Polyline )
myLineType->setCurrentIndex(0); myLineType->setCurrentIndex(0);
else else
myLineType->setCurrentIndex(1); myLineType->setCurrentIndex(1);
} }
void CurveCreator_NewSectionDlg::clear() void CurveCreator_NewSectionDlg::clear()
{ {
myName->setText(""); myName->setText("");
myIsClosed->setChecked(true); myIsClosed->setChecked(true);
myLineType->setCurrentIndex(0); myLineType->setCurrentIndex(0);
} }
void CurveCreator_NewSectionDlg::setEditMode( bool isEdit ) void CurveCreator_NewSectionDlg::setEditMode( bool isEdit )
{ {
myIsEdit = isEdit; myIsEdit = isEdit;
if( myIsEdit ){ if( myIsEdit ){
myContBtn->hide(); myContBtn->hide();
myAddBtn->setText(tr("OK")); myAddBtn->setText(tr("OK"));
} }
else{ else{
myContBtn->show(); myContBtn->show();
myAddBtn->setText(tr("ADD_BTN")); myAddBtn->setText(tr("ADD_BTN"));
} }
updateTitle(); updateTitle();
} }
QString CurveCreator_NewSectionDlg::getName() const QString CurveCreator_NewSectionDlg::getName() const
{ {
return myName->text(); return myName->text();
} }
bool CurveCreator_NewSectionDlg::isClosed() const bool CurveCreator_NewSectionDlg::isClosed() const
{ {
return myIsClosed->isChecked(); return myIsClosed->isChecked();
} }
CurveCreator::Type CurveCreator_NewSectionDlg::getSectionType() const CurveCreator::Type CurveCreator_NewSectionDlg::getSectionType() const
{ {
if( myLineType->currentIndex() == 0 ) if( myLineType->currentIndex() == 0 )
return CurveCreator::Polyline; return CurveCreator::Polyline;
else else
return CurveCreator::BSpline; return CurveCreator::BSpline;
} }
void CurveCreator_NewSectionDlg::updateTitle() void CurveCreator_NewSectionDlg::updateTitle()
{ {
QString aTitle; QString aTitle;
if( !myIsEdit ) if( !myIsEdit )
aTitle = tr("ADD_NEW_SECTION"); aTitle = tr("ADD_NEW_SECTION");
else else
aTitle = QString(tr("SET_SECTION_PARAMETERS")); aTitle = QString(tr("SET_SECTION_PARAMETERS"));
setWindowTitle(aTitle); setWindowTitle(aTitle);
} }
void CurveCreator_NewSectionDlg::setSectionName( const QString& theName ) void CurveCreator_NewSectionDlg::setSectionName( const QString& theName )
{ {
myName->setText(theName); myName->setText(theName);
} }
void CurveCreator_NewSectionDlg::onBtnClicked(QAbstractButton* theBtn ) void CurveCreator_NewSectionDlg::onBtnClicked(QAbstractButton* theBtn )
{ {
if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){ if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){
emit addSection(); emit addSection();
} }
} }

View File

@ -1,49 +1,49 @@
#ifndef CURVECREATOR_NEWSECTION_H #ifndef CURVECREATOR_NEWSECTION_H
#define CURVECREATOR_NEWSECTION_H #define CURVECREATOR_NEWSECTION_H
#include "CurveCreator.hxx" #include "CurveCreator.hxx"
#include <QDialog> #include <QDialog>
class CurveCreator_Curve; class CurveCreator_Curve;
class QLineEdit; class QLineEdit;
class QComboBox; class QComboBox;
class QCheckBox; class QCheckBox;
class QPushButton; class QPushButton;
class QAbstractButton; class QAbstractButton;
class QDialogButtonBox; class QDialogButtonBox;
class CurveCreator_NewSectionDlg : public QDialog class CurveCreator_NewSectionDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CurveCreator_NewSectionDlg(QWidget *parent = 0); explicit CurveCreator_NewSectionDlg(QWidget *parent = 0);
QString getName() const; QString getName() const;
bool isClosed() const; bool isClosed() const;
CurveCreator::Type getSectionType() const; CurveCreator::Type getSectionType() const;
void setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType ); void setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType );
void setSectionName(const QString& theName ); void setSectionName(const QString& theName );
void clear(); void clear();
void setEditMode( bool isEdit ); void setEditMode( bool isEdit );
signals: signals:
void addSection(); void addSection();
public slots: public slots:
protected slots: protected slots:
void onBtnClicked(QAbstractButton* theBtn ); void onBtnClicked(QAbstractButton* theBtn );
protected: protected:
void updateTitle(); void updateTitle();
private: private:
QLineEdit* myName; QLineEdit* myName;
QComboBox* myLineType; QComboBox* myLineType;
QCheckBox* myIsClosed; QCheckBox* myIsClosed;
bool myIsEdit; bool myIsEdit;
QPushButton* myContBtn; QPushButton* myContBtn;
QPushButton* myAddBtn; QPushButton* myAddBtn;
QDialogButtonBox* myBtnBox; QDialogButtonBox* myBtnBox;
}; };
#endif // CURVECREATOR_NEWSECTION_H #endif // CURVECREATOR_NEWSECTION_H

View File

@ -1,451 +1,451 @@
#include "CurveCreator_TreeView.h" #include "CurveCreator_TreeView.h"
#include "CurveCreator_Curve.hxx" #include "CurveCreator_Curve.hxx"
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <QHeaderView> #include <QHeaderView>
#include <QtAlgorithms> #include <QtAlgorithms>
#define ID_SECTION -1 #define ID_SECTION -1
CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ) : CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ) :
QAbstractItemModel(parent), myCurve(theCurve) QAbstractItemModel(parent), myCurve(theCurve)
{ {
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE"))); QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE")));
QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE"))); QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE")));
QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT"))); QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT")));
/* QPixmap aSplineIcon(tr(":images/ICON_SPLINE")); /* QPixmap aSplineIcon(tr(":images/ICON_SPLINE"));
QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE")); QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE"));
QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE")); QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE"));
QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE")); QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE"));
QPixmap aPointIcon(tr(":images/ICON_POINT")); */ QPixmap aPointIcon(tr(":images/ICON_POINT")); */
if( !aSplineIcon.isNull() ) if( !aSplineIcon.isNull() )
myCachedIcons[ICON_SPLINE] = aSplineIcon; myCachedIcons[ICON_SPLINE] = aSplineIcon;
if( !aPolylineIcon.isNull() ) if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_POLYLINE] = aPolylineIcon; myCachedIcons[ICON_POLYLINE] = aPolylineIcon;
if( !aPolylineIcon.isNull() ) if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon; myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon;
if( !aPolylineIcon.isNull() ) if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon; myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon;
if( !aPointIcon.isNull() ) if( !aPointIcon.isNull() )
myCachedIcons[ICON_POINT] = aPointIcon; myCachedIcons[ICON_POINT] = aPointIcon;
} }
int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const
{ {
if( parent.internalId() == ID_SECTION ) if( parent.internalId() == ID_SECTION )
return 1; return 1;
else else
return 1; return 1;
} }
QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) const QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) const
{ {
int aRow = index.row(); int aRow = index.row();
int aColumn = index.column(); int aColumn = index.column();
if( myCurve ){ if( myCurve ){
if( index.internalId() == ID_SECTION ){ if( index.internalId() == ID_SECTION ){
if( role == Qt::DisplayRole ){ if( role == Qt::DisplayRole ){
if( aColumn == 0 ) if( aColumn == 0 )
return QString::fromStdString(myCurve->getSectionName(aRow)); return QString::fromStdString(myCurve->getSectionName(aRow));
return QVariant(); return QVariant();
} }
else if( role == Qt::DecorationRole ){ else if( role == Qt::DecorationRole ){
if( aColumn == 0 ){ if( aColumn == 0 ){
CurveCreator::Type aSectionType = myCurve->getType(aRow); CurveCreator::Type aSectionType = myCurve->getType(aRow);
if( aSectionType == CurveCreator::Polyline ){ if( aSectionType == CurveCreator::Polyline ){
if( myCurve->isClosed(aRow) ){ if( myCurve->isClosed(aRow) ){
return myCachedIcons[ICON_CLOSED_POLYLINE]; return myCachedIcons[ICON_CLOSED_POLYLINE];
} }
else{ else{
return myCachedIcons[ICON_POLYLINE]; return myCachedIcons[ICON_POLYLINE];
} }
} }
else{ else{
if( myCurve->isClosed(aRow) ){ if( myCurve->isClosed(aRow) ){
return myCachedIcons[ICON_CLOSED_SPLINE]; return myCachedIcons[ICON_CLOSED_SPLINE];
} }
else{ else{
return myCachedIcons[ICON_SPLINE]; return myCachedIcons[ICON_SPLINE];
} }
} }
} }
} }
} }
else{ else{
if( role == Qt::DisplayRole ){ if( role == Qt::DisplayRole ){
if( aColumn == 1 ) if( aColumn == 1 )
return QVariant(); return QVariant();
// return "Point"; // return "Point";
else if( aColumn == 0 ){ else if( aColumn == 0 ){
CurveCreator::Coordinates aCoords = myCurve->getCoordinates(index.internalId(),index.row() ); CurveCreator::Coordinates aCoords = myCurve->getCoordinates(index.internalId(),index.row() );
QString anOut; QString anOut;
if( myCurve->getDimension() == CurveCreator::Dim2d ){ if( myCurve->getDimension() == CurveCreator::Dim2d ){
anOut = QString(tr("X=%1, Y=%2")).arg(aCoords[0]).arg(aCoords[1]); anOut = QString(tr("X=%1, Y=%2")).arg(aCoords[0]).arg(aCoords[1]);
} }
else{ else{
anOut = QString(tr("X=%1, Y=%2, Z=%3")).arg(aCoords[0]).arg(aCoords[1]).arg(aCoords[2]); anOut = QString(tr("X=%1, Y=%2, Z=%3")).arg(aCoords[0]).arg(aCoords[1]).arg(aCoords[2]);
} }
return anOut; return anOut;
} }
} }
else if( role == Qt::DecorationRole ){ else if( role == Qt::DecorationRole ){
if( aColumn == 0 ){ if( aColumn == 0 ){
return myCachedIcons[ICON_POINT]; return myCachedIcons[ICON_POINT];
} }
} }
} }
} }
return QVariant(); return QVariant();
} }
QModelIndex CurveCreator_TreeViewModel::index(int row, int column, const QModelIndex & parent ) const QModelIndex CurveCreator_TreeViewModel::index(int row, int column, const QModelIndex & parent ) const
{ {
if( parent.isValid() ){ if( parent.isValid() ){
return createIndex(row, column, parent.row() ); return createIndex(row, column, parent.row() );
} }
else{ else{
QModelIndex aParent = createIndex(row, column, ID_SECTION ); QModelIndex aParent = createIndex(row, column, ID_SECTION );
return aParent; return aParent;
} }
return QModelIndex(); return QModelIndex();
} }
QModelIndex CurveCreator_TreeViewModel::parent(const QModelIndex & theIndex) const QModelIndex CurveCreator_TreeViewModel::parent(const QModelIndex & theIndex) const
{ {
if( !theIndex.isValid() ) if( !theIndex.isValid() )
return QModelIndex(); return QModelIndex();
if( theIndex.internalId() == ID_SECTION ){ if( theIndex.internalId() == ID_SECTION ){
return QModelIndex(); return QModelIndex();
} }
return createIndex( theIndex.internalId(), 0, ID_SECTION ); return createIndex( theIndex.internalId(), 0, ID_SECTION );
} }
int CurveCreator_TreeViewModel::rowCount(const QModelIndex & parent ) const int CurveCreator_TreeViewModel::rowCount(const QModelIndex & parent ) const
{ {
int aRowCnt = 0; int aRowCnt = 0;
if( myCurve != NULL ){ if( myCurve != NULL ){
if( !parent.isValid() ){ if( !parent.isValid() ){
//Points level //Points level
aRowCnt = myCurve->getNbSections(); aRowCnt = myCurve->getNbSections();
} }
else{ else{
//Section level //Section level
if( parent.internalId() == ID_SECTION ){ if( parent.internalId() == ID_SECTION ){
aRowCnt = myCurve->getNbPoints(parent.row()); aRowCnt = myCurve->getNbPoints(parent.row());
} }
} }
} }
return aRowCnt; return aRowCnt;
} }
QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const
{ {
return createIndex( theSection, 0, ID_SECTION ); return createIndex( theSection, 0, ID_SECTION );
} }
QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const
{ {
return createIndex( thePoint, 0, theSection ); return createIndex( thePoint, 0, theSection );
} }
bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const
{ {
if( theIndx.internalId() == ID_SECTION ) if( theIndx.internalId() == ID_SECTION )
return true; return true;
return false; return false;
} }
int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const
{ {
if( theIndx.internalId() == ID_SECTION ) if( theIndx.internalId() == ID_SECTION )
return theIndx.row(); return theIndx.row();
return theIndx.internalId(); return theIndx.internalId();
} }
int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const
{ {
if( theIndx.internalId() == ID_SECTION ) if( theIndx.internalId() == ID_SECTION )
return -1; return -1;
return theIndx.row(); return theIndx.row();
} }
void CurveCreator_TreeViewModel::setCurve( CurveCreator_Curve* theCurve ) void CurveCreator_TreeViewModel::setCurve( CurveCreator_Curve* theCurve )
{ {
myCurve = theCurve; myCurve = theCurve;
reset(); reset();
} }
/*****************************************************************************************/ /*****************************************************************************************/
CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent) : CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent) :
QTreeView(parent) QTreeView(parent)
{ {
header()->hide(); header()->hide();
setUniformRowHeights(true); setUniformRowHeights(true);
setContextMenuPolicy( Qt::CustomContextMenu ); setContextMenuPolicy( Qt::CustomContextMenu );
CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this);
setModel(aModel); setModel(aModel);
setSelectionBehavior(SelectRows); setSelectionBehavior(SelectRows);
setSelectionMode(ExtendedSelection); setSelectionMode(ExtendedSelection);
setExpandsOnDoubleClick(false); setExpandsOnDoubleClick(false);
connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SIGNAL(selectionChanged()) ); this, SIGNAL(selectionChanged()) );
connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex))); connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex)));
} }
QList<int> CurveCreator_TreeView::getSelectedSections() const QList<int> CurveCreator_TreeView::getSelectedSections() const
{ {
QList<int> aSect; QList<int> aSect;
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( !aModel ) if( !aModel )
return aSect; return aSect;
QModelIndexList anIndxs = selectionModel()->selectedIndexes(); QModelIndexList anIndxs = selectionModel()->selectedIndexes();
for( int i = 0 ; i < anIndxs.size() ; i++ ){ for( int i = 0 ; i < anIndxs.size() ; i++ ){
if( aModel->isSection(anIndxs[i]) ){ if( aModel->isSection(anIndxs[i]) ){
aSect << aModel->getSection( anIndxs[i] ); aSect << aModel->getSection( anIndxs[i] );
} }
} }
qSort(aSect.begin(), aSect.end()); qSort(aSect.begin(), aSect.end());
return aSect; return aSect;
} }
void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePointsCnt ) void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePointsCnt )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
QModelIndex aSectIndx = aModel->sectionIndex( theSection ); QModelIndex aSectIndx = aModel->sectionIndex( theSection );
rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 );
} }
} }
void CurveCreator_TreeView::pointDataChanged( int theSection, int thePoint ) void CurveCreator_TreeView::pointDataChanged( int theSection, int thePoint )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
QModelIndex aPointIndx = aModel->pointIndex( theSection, thePoint ); QModelIndex aPointIndx = aModel->pointIndex( theSection, thePoint );
dataChanged( aPointIndx, aPointIndx ); dataChanged( aPointIndx, aPointIndx );
} }
} }
void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int thePointsCnt ) void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int thePointsCnt )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
for( int i = 0 ; i < thePointsCnt ; i++ ){ for( int i = 0 ; i < thePointsCnt ; i++ ){
QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i); QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i);
selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect);
} }
QModelIndex aSectIndx = aModel->sectionIndex( theSection ); QModelIndex aSectIndx = aModel->sectionIndex( theSection );
rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 );
} }
} }
void CurveCreator_TreeView::sectionAdded( int theSection ) void CurveCreator_TreeView::sectionAdded( int theSection )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
rowsInserted(QModelIndex(), theSection, theSection ); rowsInserted(QModelIndex(), theSection, theSection );
} }
} }
void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt ) void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
QModelIndex aFirstSectIndx = aModel->sectionIndex( theSection ); QModelIndex aFirstSectIndx = aModel->sectionIndex( theSection );
QModelIndex aLastSectIndx = aModel->sectionIndex( theSection + aSectCnt - 1); QModelIndex aLastSectIndx = aModel->sectionIndex( theSection + aSectCnt - 1);
dataChanged( aFirstSectIndx, aLastSectIndx ); dataChanged( aFirstSectIndx, aLastSectIndx );
} }
} }
void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt ) void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
for( int i = 0 ; i < theSectionCnt ; i++ ){ for( int i = 0 ; i < theSectionCnt ; i++ ){
QModelIndex aSectIndx = aModel->sectionIndex(theSection + i); QModelIndex aSectIndx = aModel->sectionIndex(theSection + i);
this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect);
} }
rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 ); rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 );
} }
} }
void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ) void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent )
{ {
setExpanded( theIndx, isExpanded ); setExpanded( theIndx, isExpanded );
QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select; QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select;
if( !isSelected ){ if( !isSelected ){
aFlag = QItemSelectionModel::Deselect; aFlag = QItemSelectionModel::Deselect;
} }
selectionModel()->select( theIndx, aFlag ); selectionModel()->select( theIndx, aFlag );
} }
void CurveCreator_TreeView::getIndexInfo( const QModelIndex& theIndx, bool& isExpand, bool& isSelected, bool& isCurrent ) void CurveCreator_TreeView::getIndexInfo( const QModelIndex& theIndx, bool& isExpand, bool& isSelected, bool& isCurrent )
{ {
isExpand = isExpanded(theIndx); isExpand = isExpanded(theIndx);
isSelected = selectionModel()->isSelected(theIndx); isSelected = selectionModel()->isSelected(theIndx);
isCurrent = (theIndx == selectionModel()->currentIndex()); isCurrent = (theIndx == selectionModel()->currentIndex());
} }
void CurveCreator_TreeView::swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ) void CurveCreator_TreeView::swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond )
{ {
bool isFirstSelected; bool isFirstSelected;
bool isFirstExpanded; bool isFirstExpanded;
bool isFirstCurrent; bool isFirstCurrent;
getIndexInfo( theFirst, isFirstExpanded, isFirstSelected, isFirstCurrent ); getIndexInfo( theFirst, isFirstExpanded, isFirstSelected, isFirstCurrent );
bool isSecondSelected; bool isSecondSelected;
bool isSecondExpanded; bool isSecondExpanded;
bool isSecondCurrent; bool isSecondCurrent;
getIndexInfo( theSecond, isSecondExpanded, isSecondSelected, isSecondCurrent ); getIndexInfo( theSecond, isSecondExpanded, isSecondSelected, isSecondCurrent );
setIndexState( theFirst, isSecondExpanded, isSecondSelected, isSecondCurrent ); setIndexState( theFirst, isSecondExpanded, isSecondSelected, isSecondCurrent );
setIndexState( theSecond, isFirstExpanded, isFirstSelected, isFirstCurrent ); setIndexState( theSecond, isFirstExpanded, isFirstSelected, isFirstCurrent );
dataChanged(theFirst,theFirst); dataChanged(theFirst,theFirst);
dataChanged(theSecond,theSecond); dataChanged(theSecond,theSecond);
} }
void CurveCreator_TreeView::sectionsSwapped( int theSection, int theOffset ) void CurveCreator_TreeView::sectionsSwapped( int theSection, int theOffset )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
QModelIndex aFirstIndex = aModel->sectionIndex( theSection ); QModelIndex aFirstIndex = aModel->sectionIndex( theSection );
QModelIndex aSecondIndex = aModel->sectionIndex( theSection + theOffset ); QModelIndex aSecondIndex = aModel->sectionIndex( theSection + theOffset );
swapIndexes( aFirstIndex, aSecondIndex ); swapIndexes( aFirstIndex, aSecondIndex );
} }
} }
void CurveCreator_TreeView::pointsSwapped( int theSection, int thePointNum, int theOffset ) void CurveCreator_TreeView::pointsSwapped( int theSection, int thePointNum, int theOffset )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
QModelIndex aFirstIndex = aModel->pointIndex( theSection, thePointNum ); QModelIndex aFirstIndex = aModel->pointIndex( theSection, thePointNum );
QModelIndex aSecondIndex = aModel->pointIndex( theSection, thePointNum + theOffset ); QModelIndex aSecondIndex = aModel->pointIndex( theSection, thePointNum + theOffset );
swapIndexes( aFirstIndex, aSecondIndex ); swapIndexes( aFirstIndex, aSecondIndex );
} }
} }
void CurveCreator_TreeView::setSelectedSections( const QList<int>& theList ) void CurveCreator_TreeView::setSelectedSections( const QList<int>& theList )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
selectionModel()->clearSelection(); selectionModel()->clearSelection();
for( int i = 0 ; i < theList.size() ; i++ ){ for( int i = 0 ; i < theList.size() ; i++ ){
QModelIndex aSectIndx = aModel->sectionIndex(theList[i]); QModelIndex aSectIndx = aModel->sectionIndex(theList[i]);
selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); selectionModel()->select(aSectIndx, QItemSelectionModel::Select );
} }
} }
} }
void CurveCreator_TreeView::setSelectedPoints( const QList< QPair<int, int> >& thePointsList ) void CurveCreator_TreeView::setSelectedPoints( const QList< QPair<int, int> >& thePointsList )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){ if( aModel ){
selectionModel()->clearSelection(); selectionModel()->clearSelection();
for( int i = 0 ; i < thePointsList.size() ; i++ ){ for( int i = 0 ; i < thePointsList.size() ; i++ ){
QModelIndex aSectIndx = aModel->pointIndex( thePointsList[i].first, thePointsList[i].second ); QModelIndex aSectIndx = aModel->pointIndex( thePointsList[i].first, thePointsList[i].second );
selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); selectionModel()->select(aSectIndx, QItemSelectionModel::Select );
} }
} }
} }
bool pointLessThan(const QPair<int,int> &s1, const QPair<int,int> &s2) bool pointLessThan(const QPair<int,int> &s1, const QPair<int,int> &s2)
{ {
if( s1.first < s2.first ) if( s1.first < s2.first )
return true; return true;
if( s1.first > s2.first ) if( s1.first > s2.first )
return false; return false;
return s1.second < s2.second; return s1.second < s2.second;
} }
QList< QPair< int, int > > CurveCreator_TreeView::getSelectedPoints() const QList< QPair< int, int > > CurveCreator_TreeView::getSelectedPoints() const
{ {
QList< QPair< int, int > > aPoints; QList< QPair< int, int > > aPoints;
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( !aModel ) if( !aModel )
return aPoints; return aPoints;
QModelIndexList anIndxs = selectionModel()->selectedIndexes(); QModelIndexList anIndxs = selectionModel()->selectedIndexes();
for( int i = 0 ; i < anIndxs.size() ; i++ ){ for( int i = 0 ; i < anIndxs.size() ; i++ ){
if( !aModel->isSection( anIndxs[i] ) ){ if( !aModel->isSection( anIndxs[i] ) ){
int aSect = aModel->getSection(anIndxs[i]); int aSect = aModel->getSection(anIndxs[i]);
int aPointNum = aModel->getPoint(anIndxs[i]); int aPointNum = aModel->getPoint(anIndxs[i]);
QPair< int, int > aPoint = QPair<int,int>( aSect, aPointNum ); QPair< int, int > aPoint = QPair<int,int>( aSect, aPointNum );
aPoints.push_back( aPoint ); aPoints.push_back( aPoint );
} }
} }
qSort( aPoints.begin(), aPoints.end(), pointLessThan ); qSort( aPoints.begin(), aPoints.end(), pointLessThan );
return aPoints; return aPoints;
} }
CurveCreator_TreeView::SelectionType CurveCreator_TreeView::getSelectionType() const CurveCreator_TreeView::SelectionType CurveCreator_TreeView::getSelectionType() const
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( !aModel ) if( !aModel )
return ST_NOSEL; return ST_NOSEL;
bool isPointSel = false; bool isPointSel = false;
bool isSectSel = false; bool isSectSel = false;
bool isOneSection = true; bool isOneSection = true;
int aSectNum = -1; int aSectNum = -1;
QModelIndexList aLst = selectionModel()->selectedIndexes(); QModelIndexList aLst = selectionModel()->selectedIndexes();
for( int i = 0 ; i < aLst.size() ; i++ ){ for( int i = 0 ; i < aLst.size() ; i++ ){
if( aModel->isSection( aLst[i] ) ){ if( aModel->isSection( aLst[i] ) ){
isSectSel = true; isSectSel = true;
} }
else{ else{
isPointSel = true; isPointSel = true;
if( aSectNum == -1 ){ if( aSectNum == -1 ){
aSectNum = aModel->getSection(aLst[i]); aSectNum = aModel->getSection(aLst[i]);
} }
else{ else{
if( aSectNum != aModel->getSection( aLst[i] ) ){ if( aSectNum != aModel->getSection( aLst[i] ) ){
isOneSection = false; isOneSection = false;
} }
} }
} }
} }
if( isSectSel && !isPointSel ) if( isSectSel && !isPointSel )
return ST_SECTIONS; return ST_SECTIONS;
if( isPointSel && !isSectSel ){ if( isPointSel && !isSectSel ){
if( isOneSection ){ if( isOneSection ){
return ST_POINTS_ONE_SECTION; return ST_POINTS_ONE_SECTION;
} }
return ST_POINTS; return ST_POINTS;
} }
if( isPointSel && isSectSel ) if( isPointSel && isSectSel )
return ST_MIXED; return ST_MIXED;
return ST_NOSEL; return ST_NOSEL;
} }
void CurveCreator_TreeView::onActivated( QModelIndex theIndx ) void CurveCreator_TreeView::onActivated( QModelIndex theIndx )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( !aModel ) if( !aModel )
return; return;
int aSect = aModel->getSection(theIndx); int aSect = aModel->getSection(theIndx);
if( aModel->isSection(theIndx) ){ if( aModel->isSection(theIndx) ){
emit sectionEntered( aSect ); emit sectionEntered( aSect );
return; return;
} }
int aPointNum = aModel->getPoint( theIndx ); int aPointNum = aModel->getPoint( theIndx );
emit pointEntered( aSect, aPointNum ); emit pointEntered( aSect, aPointNum );
} }
void CurveCreator_TreeView::setCurve( CurveCreator_Curve* theCurve ) void CurveCreator_TreeView::setCurve( CurveCreator_Curve* theCurve )
{ {
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model()); CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ) if( aModel )
aModel->setCurve(theCurve); aModel->setCurve(theCurve);
reset(); reset();
} }

View File

@ -1,75 +1,75 @@
#ifndef CURVECREATOR_TREEVIEW_H #ifndef CURVECREATOR_TREEVIEW_H
#define CURVECREATOR_TREEVIEW_H #define CURVECREATOR_TREEVIEW_H
#include <QTreeView> #include <QTreeView>
#include <QAbstractItemModel> #include <QAbstractItemModel>
class CurveCreator_Curve; class CurveCreator_Curve;
class CurveCreator_TreeViewModel : public QAbstractItemModel class CurveCreator_TreeViewModel : public QAbstractItemModel
{ {
public: public:
CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ); CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent );
virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex & theIndex) const; virtual QModelIndex parent(const QModelIndex & theIndex) const;
QModelIndex sectionIndex( int theSection ) const; QModelIndex sectionIndex( int theSection ) const;
QModelIndex pointIndex( int theSection, int thePoint ) const; QModelIndex pointIndex( int theSection, int thePoint ) const;
bool isSection( const QModelIndex& theIndx ) const; bool isSection( const QModelIndex& theIndx ) const;
int getSection( const QModelIndex& theIndx ) const; int getSection( const QModelIndex& theIndx ) const;
int getPoint( const QModelIndex& theIndx ) const; int getPoint( const QModelIndex& theIndx ) const;
void setCurve( CurveCreator_Curve* theCurve ); void setCurve( CurveCreator_Curve* theCurve );
private: private:
enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT }; enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT };
private: private:
CurveCreator_Curve* myCurve; CurveCreator_Curve* myCurve;
QMap<IconType, QPixmap> myCachedIcons; QMap<IconType, QPixmap> myCachedIcons;
}; };
class CurveCreator_TreeView : public QTreeView class CurveCreator_TreeView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED }; enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED };
public: public:
explicit CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent = 0); explicit CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent = 0);
SelectionType getSelectionType() const; SelectionType getSelectionType() const;
QList<int> getSelectedSections() const; QList<int> getSelectedSections() const;
QList< QPair< int, int > > getSelectedPoints() const; QList< QPair< int, int > > getSelectedPoints() const;
void pointsAdded( int theSection, int thePoint, int thePointsCnt=1 ); void pointsAdded( int theSection, int thePoint, int thePointsCnt=1 );
void pointDataChanged( int theSection, int thePoint ); void pointDataChanged( int theSection, int thePoint );
void pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 ); void pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 );
void pointsSwapped( int theSection, int thePointNum, int theOffset ); void pointsSwapped( int theSection, int thePointNum, int theOffset );
void sectionAdded( int theSection ); void sectionAdded( int theSection );
void sectionChanged(int theSection , int aSectCnt = 1); void sectionChanged(int theSection , int aSectCnt = 1);
void sectionsRemoved( int theSection, int theSectionCnt=1 ); void sectionsRemoved( int theSection, int theSectionCnt=1 );
void sectionsSwapped( int theSection, int theOffset ); void sectionsSwapped( int theSection, int theOffset );
void setSelectedSections( const QList<int>& theList ); void setSelectedSections( const QList<int>& theList );
void setSelectedPoints( const QList< QPair<int, int> >& thePointsList ); void setSelectedPoints( const QList< QPair<int, int> >& thePointsList );
void setCurve( CurveCreator_Curve* theCurve ); void setCurve( CurveCreator_Curve* theCurve );
signals: signals:
void selectionChanged(); void selectionChanged();
void sectionEntered(int); void sectionEntered(int);
void pointEntered(int,int); void pointEntered(int,int);
public slots: public slots:
protected slots: protected slots:
void onActivated( QModelIndex theIndx ); void onActivated( QModelIndex theIndx );
protected: protected:
void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ); void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond );
void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
}; };
#endif // CURVECREATOR_TREEVIEW_H #endif // CURVECREATOR_TREEVIEW_H

File diff suppressed because it is too large Load Diff

View File

@ -1,75 +1,75 @@
#ifndef CURVECREATOR_WIDGET_H #ifndef CURVECREATOR_WIDGET_H
#define CURVECREATOR_WIDGET_H #define CURVECREATOR_WIDGET_H
#include "CurveCreator_Curve.hxx" #include "CurveCreator_Curve.hxx"
#include <QWidget> #include <QWidget>
#include <QMap> #include <QMap>
class QAction; class QAction;
class QPixmap; class QPixmap;
class CurveCreator_CurveEditor; class CurveCreator_CurveEditor;
class CurveCreator_TreeView; class CurveCreator_TreeView;
class CurveCreator_NewPointDlg; class CurveCreator_NewPointDlg;
class CurveCreator_NewSectionDlg; class CurveCreator_NewSectionDlg;
class CurveCreator_Widget : public QWidget class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CurveCreator_Widget( QWidget* parent, explicit CurveCreator_Widget( QWidget* parent,
CurveCreator_Curve *theCurve, CurveCreator_Curve *theCurve,
Qt::WindowFlags fl=0 ); Qt::WindowFlags fl=0 );
void setCurve( CurveCreator_Curve* theCurve ); void setCurve( CurveCreator_Curve* theCurve );
signals: signals:
public slots: public slots:
protected slots: protected slots:
void onNewPoint(); void onNewPoint();
void onNewSection(); void onNewSection();
void onSelectionChanged(); void onSelectionChanged();
void onAddNewPoint(); void onAddNewPoint();
void onAddNewSection(); void onAddNewSection();
void onEditSection( int theSection ); void onEditSection( int theSection );
void onEditPoint( int theSection, int thePoint ); void onEditPoint( int theSection, int thePoint );
void onJoin(); void onJoin();
void onRemove(); void onRemove();
void onMoveUp(); void onMoveUp();
void onMoveDown(); void onMoveDown();
void onClearAll(); void onClearAll();
void onJoinAll(); void onJoinAll();
void onInsertSectionBefore(); void onInsertSectionBefore();
void onInsertSectionAfter(); void onInsertSectionAfter();
void onSetSpline(); void onSetSpline();
void onSetPolyline(); void onSetPolyline();
void onCloseSections(); void onCloseSections();
void onUncloseSections(); void onUncloseSections();
void onInsertPointBefore(); void onInsertPointBefore();
void onInsertPointAfter(); void onInsertPointAfter();
void onUndoSettings(); void onUndoSettings();
void onContextMenu(QPoint thePoint); void onContextMenu(QPoint thePoint);
protected: protected:
enum ActionId{ UNDO_ID, REDO_ID, NEW_SECTION_ID, NEW_POINT_ID, REMOVE_ID, REMOVE_ALL_ID, JOIN_ID, enum ActionId{ UNDO_ID, REDO_ID, NEW_SECTION_ID, NEW_POINT_ID, REMOVE_ID, REMOVE_ALL_ID, JOIN_ID,
JOIN_ALL_ID, UP_ID, DOWN_ID, INSERT_SECTION_BEFORE_ID, INSERT_SECTION_AFTER_ID, JOIN_ALL_ID, UP_ID, DOWN_ID, INSERT_SECTION_BEFORE_ID, INSERT_SECTION_AFTER_ID,
INSERT_POINT_BEFORE_ID, INSERT_POINT_AFTER_ID, CLOSE_SECTIONS_ID, UNCLOSE_SECTIONS_ID, INSERT_POINT_BEFORE_ID, INSERT_POINT_AFTER_ID, CLOSE_SECTIONS_ID, UNCLOSE_SECTIONS_ID,
SET_SECTIONS_POLYLINE_ID, SET_SECTIONS_SPLINE_ID, CLEAR_ALL_ID, SEPARATOR_ID }; SET_SECTIONS_POLYLINE_ID, SET_SECTIONS_SPLINE_ID, CLEAR_ALL_ID, SEPARATOR_ID };
private: private:
QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage, QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
const QString& theToolTip, const QKeySequence& theShortcut ); const QString& theToolTip, const QKeySequence& theShortcut );
QAction* getAction(ActionId theId); QAction* getAction(ActionId theId);
private: private:
QMap<ActionId, QAction*> myActionMap; QMap<ActionId, QAction*> myActionMap;
CurveCreator_Curve* myCurve; CurveCreator_Curve* myCurve;
CurveCreator_CurveEditor* myEdit; CurveCreator_CurveEditor* myEdit;
CurveCreator_TreeView* mySectionView; CurveCreator_TreeView* mySectionView;
CurveCreator_NewPointDlg* myNewPointEditor; CurveCreator_NewPointDlg* myNewPointEditor;
CurveCreator_NewSectionDlg* myNewSectionEditor; CurveCreator_NewSectionDlg* myNewSectionEditor;
int mySection; int mySection;
int myPointNum; int myPointNum;
}; };
#endif // CURVECREATOR_WIDGET_H #endif // CURVECREATOR_WIDGET_H

View File

@ -55,7 +55,7 @@ salomeinclude_HEADERS = \
if GEOM_ENABLE_GUI if GEOM_ENABLE_GUI
dist_libCurveCreator_la_SOURCES += \ dist_libCurveCreator_la_SOURCES += \
CurveCreator_NewPointDlg.h \ CurveCreator_NewPointDlg.h \
CurveCreator_NewSection.h \ CurveCreator_NewSectionDlg.h \
CurveCreator_TreeView.h \ CurveCreator_TreeView.h \
CurveCreator_Widget.h \ CurveCreator_Widget.h \
CurveCreator_NewPointDlg.cxx \ CurveCreator_NewPointDlg.cxx \
@ -87,5 +87,7 @@ libCurveCreator_la_CPPFLAGS = \
$(GUI_CXXFLAGS) $(GUI_CXXFLAGS)
libCurveCreator_la_LDFLAGS = \ libCurveCreator_la_LDFLAGS = \
$(KERNEL_LDFLAGS) \ $(QT_MT_LIBS) \
$(CAS_KERNEL) $(CAS_KERNEL) \
$(KERNEL_LDFLAGS) \
$(GUI_LDFLAGS) -lqtx -lsuit