CurveCreator was updated

This commit is contained in:
mtn 2013-08-21 06:46:20 +00:00
parent 9b88d11eb3
commit 2c4464497c
11 changed files with 941 additions and 1349 deletions

View File

@ -33,6 +33,8 @@
#include <CurveCreator_Macro.hxx>
#include <CurveCreator_Operation.hxx>
#include <QString>
class CurveCreator_Section;
@ -40,7 +42,7 @@ class CurveCreator_Section;
* The CurveCreator_Curve object is represented as one or more sets of
* connected points; thus CurveCreator_Curve object can contain several
* not connected curves (polylines or b-splines), each such curve has two
* only ends start and end points in other words non-manifold curves
* only ends <EFBFBD> start and end points <EFBFBD> in other words non-manifold curves
* are not supported.
*/
class CURVECREATOR_EXPORT CurveCreator_Curve
@ -83,7 +85,7 @@ public:
//! Get type of the specified section
CurveCreator::Type getType(const int theISection) const;
//! Get “closed” flag of the specified section
//! Get <EFBFBD>closed<EFBFBD> flag of the specified section
bool isClosed(const int theISection) const;
//! Returns specifyed section name
@ -144,7 +146,7 @@ protected:
const int theISection,
const int theIPnt);
/** Set “closed” flag of the specified section (all sections if
/** Set <EFBFBD>closed<EFBFBD> flag of the specified section (all sections if
* \a theISection is -1).
*/
void setClosed(const bool theIsClosed, const int theISection = -1);

View File

@ -60,7 +60,7 @@ public:
//! Undo previous operation
void undo();
//! Redo last previously “undoed” operation
//! Redo last previously <EFBFBD>undoed<EFBFBD> operation
void redo();
//! Get number of available undo operations

View File

@ -28,11 +28,14 @@ CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDi
aCoordLay->addWidget(aLbl, 1, 0 );
aCoordLay->addWidget(myY, 1, 1 );
if( theDim == CurveCreator::Dim3d ){
aLbl = new QLabel( tr("Z_COORD"), this);
myZLabel = new QLabel( tr("Z_COORD"), this);
myZ = new QDoubleSpinBox(this);
aCoordLay->addWidget(aLbl, 2,0 );
aCoordLay->addWidget(myZLabel, 2,0 );
aCoordLay->addWidget(myZ, 2,1 );
if( theDim != CurveCreator::Dim3d ){
myZ->hide();
myZLabel->hide();
}
myBtnBox = new QDialogButtonBox(this);
@ -95,7 +98,7 @@ CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const
aCoords.push_back(anX);
double anY = myY->value();
aCoords.push_back(anY);
if( myZ ){
if( myZ->isVisible() ){
double aZ = myZ->value();
aCoords.push_back(aZ);
}
@ -113,17 +116,28 @@ void CurveCreator_NewPointDlg::clear()
{
initSpinBox(myX);
initSpinBox(myY);
if( myZ )
initSpinBox(myZ);
}
void CurveCreator_NewPointDlg::setDimension(CurveCreator::Dimension theDim)
{
if( theDim == CurveCreator::Dim2d ){
myZ->hide();
myZLabel->hide();
}
else{
myZ->show();
myZLabel->show();
}
}
void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords )
{
double anX = theCoords[0];
myX->setValue(anX);
double anY = theCoords[1];
myY->setValue(anY);
if( myZ && ( theCoords.size() == 3)){
if( theCoords.size() == 3 ){
double aZ = theCoords[2];
myZ->setValue(aZ);
}

View File

@ -9,6 +9,7 @@ class QDoubleSpinBox;
class QDialogButtonBox;
class QAbstractButton;
class QPushButton;
class QLabel;
class CurveCreator_NewPointDlg : public QDialog
{
@ -20,6 +21,7 @@ public:
void setSectionName( const QString& theName );
void setEditMode( bool isEdit );
void setCoordinates( const CurveCreator::Coordinates& theCoords );
void setDimension(CurveCreator::Dimension theDim);
signals:
void addPoint();
public slots:
@ -34,6 +36,7 @@ private:
QDoubleSpinBox* myX;
QDoubleSpinBox* myY;
QDoubleSpinBox* myZ;
QLabel* myZLabel;
QPushButton* myContBtn;
QPushButton* myAddBtn;
bool myIsEdit;

View File

@ -1,5 +1,4 @@
#include "CurveCreator_NewSectionDlg.h"
#include "CurveCreator_Curve.hxx"
#include <SUIT_Session.h>
@ -25,10 +24,15 @@ CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) :
aLbl = new QLabel(tr("LINE_TYPE"));
myLineType = new QComboBox(this);
QPixmap aPolylineImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
myLineType->addItem(aPolylineImage, tr("POLYLINE_TYPE"));
QPixmap aSplineImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
myLineType->addItem(aSplineImage,tr("SPLINE_TYPE"));
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
// QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
// QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE"));
myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE"));
myLineType->setCurrentIndex(0);
aLay->addWidget(aLbl, 1, 0);
aLay->addWidget(myLineType, 1 , 1);
@ -59,6 +63,8 @@ void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, b
myIsClosed->setChecked(isClosed);
if( theType == CurveCreator::Polyline )
myLineType->setCurrentIndex(0);
else
myLineType->setCurrentIndex(1);
}
void CurveCreator_NewSectionDlg::clear()

View File

@ -1,5 +1,4 @@
#include "CurveCreator_TreeView.h"
#include "CurveCreator_Curve.hxx"
#include <SUIT_Session.h>
@ -13,23 +12,31 @@
CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ) :
QAbstractItemModel(parent), myCurve(theCurve)
{
QPixmap aSplineIcon(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE")));
QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE")));
QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT")));
/* QPixmap aSplineIcon(tr(":images/ICON_SPLINE"));
QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE"));
QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE"));
QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE"));
QPixmap aPointIcon(tr(":images/ICON_POINT")); */
if( !aSplineIcon.isNull() )
myCachedIcons[ICON_SPLINE] = aSplineIcon;
QPixmap aPolylineIcon(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_POLYLINE] = aPolylineIcon;
QPixmap aClosedPolylineIcon(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE")));
if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon;
QPixmap aClosedSplineIcon(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE")));
if( !aPolylineIcon.isNull() )
myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon;
QPixmap aPointIcon(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POINT")));
if( !aPointIcon.isNull() )
myCachedIcons[ICON_POINT] = aPointIcon;
@ -175,6 +182,12 @@ int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const
return theIndx.row();
}
void CurveCreator_TreeViewModel::setCurve( CurveCreator_Curve* theCurve )
{
myCurve = theCurve;
reset();
}
/*****************************************************************************************/
CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent) :
QTreeView(parent)
@ -230,6 +243,10 @@ void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int the
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){
for( int i = 0 ; i < thePointsCnt ; i++ ){
QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i);
selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect);
}
QModelIndex aSectIndx = aModel->sectionIndex( theSection );
rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 );
}
@ -257,7 +274,11 @@ void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt )
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel ){
this->rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 );
for( int i = 0 ; i < theSectionCnt ; i++ ){
QModelIndex aSectIndx = aModel->sectionIndex(theSection + i);
this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect);
}
rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 );
}
}
@ -420,3 +441,11 @@ void CurveCreator_TreeView::onActivated( QModelIndex theIndx )
int aPointNum = aModel->getPoint( theIndx );
emit pointEntered( aSect, aPointNum );
}
void CurveCreator_TreeView::setCurve( CurveCreator_Curve* theCurve )
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(model());
if( aModel )
aModel->setCurve(theCurve);
reset();
}

View File

@ -22,6 +22,9 @@ public:
bool isSection( const QModelIndex& theIndx ) const;
int getSection( const QModelIndex& theIndx ) const;
int getPoint( const QModelIndex& theIndx ) const;
void setCurve( CurveCreator_Curve* theCurve );
private:
enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT };
private:
@ -53,6 +56,8 @@ public:
void setSelectedSections( const QList<int>& theList );
void setSelectedPoints( const QList< QPair<int, int> >& thePointsList );
void setCurve( CurveCreator_Curve* theCurve );
signals:
void selectionChanged();
void sectionEntered(int);
@ -64,8 +69,7 @@ protected:
void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond );
void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
private:
CurveCreator_Curve* myCurve;
};
#endif // CURVECREATOR_TREEVIEW_H

View File

@ -1,547 +0,0 @@
#include "CurveCreator_Widget.h"
#include "CurveCreator_TreeView.h"
#include "QVBoxLayout"
#include "CurveCreator_Curve.hxx"
#include "CurveCreator_CurveEditor.hxx"
#include "CurveCreator.hxx"
#include "CurveCreator_NewPointDlg.h"
#include "CurveCreator_NewSectionDlg.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QGroupBox>
#include <QToolButton>
#include <QToolBar>
#include <QAction>
#include <QMenu>
CurveCreator_Widget::CurveCreator_Widget(QWidget *parent) :
QWidget(parent), myNewPointEditor(NULL)
{
//TODO remove it for debug only
myCurve = new CurveCreator_Curve(CurveCreator::Dim2d);
myEdit = new CurveCreator_CurveEditor( myCurve );
CurveCreator::Coordinates aCoords;
aCoords.push_back(10);
aCoords.push_back(20);
aCoords.push_back(1);
aCoords.push_back(2);
myEdit->addSection("",CurveCreator::BSpline, true, aCoords );
aCoords.clear();
aCoords.push_back(11);
aCoords.push_back(21);
aCoords.push_back(111);
aCoords.push_back(211);
aCoords.push_back(101);
aCoords.push_back(201);
aCoords.push_back(13);
aCoords.push_back(25);
myEdit->addSection("",CurveCreator::Polyline, false, aCoords );
aCoords.clear();
for( int i = 0 ; i < 1000000 ; i++ ){
double anX = ((double)i)/10000.;
double anY = ((double)i)/10000. + 3.4;
aCoords.push_back(anX);
aCoords.push_back(anY);
}
myEdit->addSection("",CurveCreator::Polyline, true, aCoords );
//TODO end debug
myNewPointEditor = new CurveCreator_NewPointDlg(myCurve->getDimension(), this);
connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()));
myNewSectionEditor = new CurveCreator_NewSectionDlg(this);
connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()));
QHBoxLayout* aNameLayout = new QHBoxLayout();
QLabel* aNameLabel = new QLabel(tr("CURVE_NAME_TLT"), this);
aNameLayout->addWidget(aNameLabel);
QLineEdit* aNameEdit = new QLineEdit(this);
aNameLayout->addWidget(aNameEdit);
QGroupBox* aSectionGroup = new QGroupBox(tr("SECTION_GROUP_TLT"),this);
mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
connect( mySectionView, SIGNAL(pointEntered(int,int)), this, SLOT(onEditPoint(int,int)) );
connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
// QToolButton* anUndoBtn = new QToolButton(aTB);
QAction* anAct = createAction( UNDO_ID, tr("UNDO"), tr(":images/ICON_UNDO"), tr("UNDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
aTB->addAction(anAct);
anAct = createAction( REDO_ID, tr("REDO"), tr(":images/ICON_REDO"), tr("REDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
aTB->addAction(anAct);
aTB->addSeparator();
anAct = createAction( NEW_SECTION_ID, tr("ICON_NEW_SECTION"), tr(":images/ICON_NEW_SECTION"), tr("NEW_SECTION_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_N) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
aTB->addAction(anAct);
anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), tr(":images/ICON_INSERT_SECTION_BEFORE"), tr("INSERT_SECTION_BEFORE_TLT"),
QKeySequence(Qt::ControlModifier | Qt::Key_Insert ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionBefore()) );
anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), tr(":images/ICON_INSERT_SECTION_AFTER"), tr("INSERT_SECTION_AFTER_TLT"),
QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Insert ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionAfter()) );
anAct = createAction( NEW_POINT_ID, tr("ICON_NEW_POINT"), tr(":images/ICON_NEW_POINT"), tr("NEW_POINT_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_P) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onNewPoint()) );
aTB->addAction(anAct);
aTB->addSeparator();
anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), tr(":images/ICON_POINT_BEFORE"), tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointBefore()) );
anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), tr(":images/ICON_POINT_AFTER"), tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointAfter()) );
anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), tr(":images/ICON_CLOSE_SECTIONS"), tr("CLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_W) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), tr(":images/ICON_UNCLOSE_SECTIONS"), tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), tr(":images/ICON_POLYLINE"), tr("SET_POLYLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_E) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), tr(":images/ICON_SPLINE"), tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
anAct = createAction( REMOVE_ID, tr("ICON_REMOVE"), tr(":images/ICON_REMOVE"), tr("REMOVE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
aTB->addAction(anAct);
aTB->addSeparator();
anAct = createAction( JOIN_ID, tr("ICON_JOIN"), tr(":images/ICON_JOIN"), tr("JOIN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
aTB->addAction(anAct);
aTB->addSeparator();
anAct = createAction( UP_ID, tr("ICON_STEP_UP"), tr(":images/ICON_STEP_UP"), tr("STEP_UP_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Up ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveUp()) );
aTB->addAction(anAct);
anAct = createAction( DOWN_ID, tr("ICON_STEP_DOWN"), tr(":images/ICON_STEP_DOWN"), tr("STEP_DOWN"), QKeySequence(Qt::ControlModifier|Qt::Key_Down ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveDown()) );
aTB->addAction(anAct);
anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), tr(":images/ICON_CLEAR_ALL"), tr("CLEAR_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
aTB->addAction(anAct);
anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), tr(":images/ICON_JOIN_ALL"), tr("JOIN_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
aTB->addAction(anAct);
QVBoxLayout* aSectLayout = new QVBoxLayout();
aSectLayout->addWidget(aTB);
aSectLayout->addWidget(mySectionView);
aSectionGroup->setLayout(aSectLayout);
QVBoxLayout* aLay = new QVBoxLayout();
aLay->addLayout(aNameLayout);
aLay->addWidget(aSectionGroup);
setLayout(aLay);
onSelectionChanged();
}
void CurveCreator_Widget::onSelectionChanged()
{
QList<ActionId> anEnabledAct;
anEnabledAct << NEW_SECTION_ID;
int aSectCnt = myCurve->getNbPoints();
if( aSectCnt > 0 )
anEnabledAct << CLEAR_ALL_ID;
if( aSectCnt > 1 )
anEnabledAct << JOIN_ALL_ID;
QList<int> aSelSections = mySectionView->getSelectedSections();
QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
switch( aSelType ){
case CurveCreator_TreeView::ST_NOSEL:{
break;
}
case CurveCreator_TreeView::ST_SECTIONS:{
if( aSelSections.size() > 1 ){
anEnabledAct << JOIN_ID;
}
if( aSelSections[0] > 0 ){
anEnabledAct << UP_ID;
}
if( aSelSections.size() == 1 ){
anEnabledAct << NEW_POINT_ID << INSERT_SECTION_BEFORE_ID << INSERT_SECTION_AFTER_ID;
}
if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
anEnabledAct << DOWN_ID;
}
anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
break;
}
case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
if( aSelPoints[0].second > 0 ){
anEnabledAct << UP_ID;
}
int aLastIndex = aSelPoints.size()-1;
int aSect = aSelPoints[0].first;
if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
anEnabledAct << DOWN_ID;
}
if( aSelPoints.size() == 1){
anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
}
break;
}
}
int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
if( aSelObjsCnt > 0 ){
anEnabledAct << REMOVE_ID;
}
if( myCurve->getNbSections() > 0 ){
anEnabledAct << REMOVE_ALL_ID;
}
if( myCurve->getNbSections() > 1 ){
anEnabledAct << JOIN_ALL_ID;
}
QList<ActionId> anIds = myActionMap.keys();
for( int i = 0 ; i < anIds.size() ; i++ ){
if( myActionMap.contains(anIds[i]) ){
if( anEnabledAct.contains(anIds[i]) ){
myActionMap[anIds[i]]->setEnabled(true);
}
else{
myActionMap[anIds[i]]->setEnabled(false);
}
}
}
}
void CurveCreator_Widget::onNewPoint()
{
mySection= -1;
myPointNum = -1;
QList<int> aSelSection = mySectionView->getSelectedSections();
if( aSelSection.size() > 0 ){
mySection = aSelSection[0];
}
else{
QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
if( aSelPoints.size() > 0 ){
mySection = aSelPoints[0].first;
myPointNum = aSelPoints[0].second + 1;
}
}
QString aSectName;
if( mySection < 0 ){
mySection = myCurve->getNbSections() - 1;
}
aSectName = QString::fromStdString( myCurve->getSectionName(mySection));
if( myPointNum < 0 ){
myPointNum = myCurve->getNbPoints(mySection);
}
myNewPointEditor->clear();
myNewPointEditor->setEditMode(false);
myNewPointEditor->setSectionName(aSectName);
if( myNewPointEditor->exec() == QDialog::Accepted ){
onAddNewPoint();
}
}
void CurveCreator_Widget::onAddNewPoint()
{
CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
myEdit->insertPoints(aCoords, mySection, myPointNum );
mySectionView->pointsAdded( mySection, myPointNum );
myNewPointEditor->clear();
myPointNum++;
}
void CurveCreator_Widget::onNewSection()
{
myNewSectionEditor->clear();
myNewSectionEditor->setEditMode(false);
QString aSectName = QString( myCurve->getUnicSectionName().c_str() );
myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
if( myNewSectionEditor->exec() == QDialog::Accepted ){
onAddNewSection();
}
}
void CurveCreator_Widget::onAddNewSection()
{
CurveCreator::Coordinates aCoords;
myEdit->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
myNewSectionEditor->isClosed(), aCoords );
mySectionView->sectionAdded( mySection );
QString aNewName = QString(myCurve->getUnicSectionName().c_str());
myNewSectionEditor->setSectionName(aNewName);
mySection++;
}
QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QString& theImageName,
const QString& theToolTip, const QKeySequence& theShortcut )
{
QAction* anAct = new QAction(theName,this);
QIcon anIcon(theImageName);
if( !anIcon.isNull() ){
anAct->setIcon(anIcon);
}
anAct->setShortcut(theShortcut);
anAct->setToolTip(theToolTip);
myActionMap[theId] = anAct;
return anAct;
}
QAction* CurveCreator_Widget::getAction(ActionId theId)
{
if( myActionMap.contains(theId) )
return myActionMap[theId];
return NULL;
}
void CurveCreator_Widget::onEditSection( int theSection )
{
mySection = theSection;
QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
bool isClosed = myCurve->isClosed(theSection);
CurveCreator::Type aType = myCurve->getType(theSection);
myNewSectionEditor->setEditMode(true);
myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
if( myNewSectionEditor->exec() == QDialog::Accepted ){
QString aName = myNewSectionEditor->getName();
bool isClosed = myNewSectionEditor->isClosed();
CurveCreator::Type aSectType = myNewSectionEditor->getSectionType();
myEdit->setClosed( isClosed, mySection );
myEdit->setName( aName.toStdString(), mySection );
myEdit->setType( aSectType, mySection );
mySectionView->sectionChanged(mySection);
}
}
void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
{
if( !myNewPointEditor ){
}
QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
myNewPointEditor->setEditMode(true);
myNewPointEditor->setSectionName(aSectName);
CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
myNewPointEditor->setCoordinates(aCoords);
if( myNewPointEditor->exec() == QDialog::Accepted ){
aCoords = myNewPointEditor->getCoordinates();
myEdit->setCoordinates(aCoords, theSection, thePoint);
mySectionView->pointDataChanged(theSection, thePoint );
}
}
void CurveCreator_Widget::onJoin()
{
QList<int> aSections = mySectionView->getSelectedSections();
if( aSections.size() == 0 ){
return;
}
int aMainSect = aSections[0];
int aMainSectSize = myCurve->getNbPoints(aMainSect);
for( int i = 1 ; i < aSections.size() ; i++ ){
int aSectNum = aSections[i] - (i-1);
myEdit->join( aMainSect, aSectNum );
mySectionView->sectionsRemoved( aSectNum );
}
int aNewSectSize = myCurve->getNbPoints(aMainSect);
if( aNewSectSize != aMainSectSize )
mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
}
void CurveCreator_Widget::onRemove()
{
QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
int aCurrSect=-1;
int aRemoveCnt = 0;
for( int i = 0 ; i < aSelPoints.size() ; i++ ){
if( aCurrSect != aSelPoints[i].first ){
aRemoveCnt = 0;
aCurrSect = aSelPoints[i].first;
}
int aPntIndx = aSelPoints[i].second - aRemoveCnt;
myEdit->removePoints(aCurrSect,aPntIndx, 1);
mySectionView->pointsRemoved( aCurrSect, aPntIndx );
aRemoveCnt++;
}
QList<int> aSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSections.size() ; i++ ){
int aSectNum = aSections[i] - (i);
myEdit->removeSection( aSectNum );
mySectionView->sectionsRemoved( aSectNum );
}
mySectionView->clearSelection();
}
void CurveCreator_Widget::onMoveUp()
{
if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
//Move sections
QList<int> aSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSections.size() ; i++ ){
int anIndx = aSections[i];
myEdit->moveSection( anIndx, anIndx-1);
mySectionView->sectionsSwapped( anIndx, -1 );
}
}
else{
//Move points
QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();
for( int i = 0 ; i < aPoints.size() ; i++ ){
int aSection = aPoints[i].first;
int aPoint = aPoints[i].second;
myEdit->movePoint(aSection, aPoint, aPoint-2);
mySectionView->pointsSwapped( aSection, aPoint, -1 );
}
}
}
void CurveCreator_Widget::onMoveDown()
{
if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
//Move sections
QList<int> aSections = mySectionView->getSelectedSections();
for( int i = aSections.size()-1 ; i >=0 ; i-- ){
int anIndx = aSections[i];
myEdit->moveSection( anIndx, anIndx+1);
mySectionView->sectionsSwapped( anIndx, 1 );
}
}
else{
//Move points
QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();
for( int i = aPoints.size() - 1; i >= 0 ; i-- ){
int aSection = aPoints[i].first;
int aPoint = aPoints[i].second;
myEdit->movePoint(aSection, aPoint, aPoint+1);
mySectionView->pointsSwapped( aSection, aPoint, 1 );
}
}
}
void CurveCreator_Widget::onClearAll()
{
myEdit->clear();
mySectionView->reset();
onSelectionChanged();
}
void CurveCreator_Widget::onJoinAll()
{
myEdit->join();
mySectionView->reset();
onSelectionChanged();
}
void CurveCreator_Widget::onInsertSectionBefore()
{
}
void CurveCreator_Widget::onInsertSectionAfter()
{
}
void CurveCreator_Widget::onInsertPointBefore()
{
}
void CurveCreator_Widget::onInsertPointAfter()
{
}
void CurveCreator_Widget::onUndoSettings()
{
}
void CurveCreator_Widget::onSetSpline()
{
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::BSpline, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
}
void CurveCreator_Widget::onSetPolyline()
{
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::Polyline, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
}
void CurveCreator_Widget::onCloseSections()
{
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(true, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
}
void CurveCreator_Widget::onUncloseSections()
{
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(false, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
}
void CurveCreator_Widget::onContextMenu( QPoint thePoint )
{
QList<ActionId> aContextActions;
aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
INSERT_SECTION_BEFORE_ID << INSERT_SECTION_AFTER_ID << SEPARATOR_ID <<
CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
SET_SECTIONS_SPLINE_ID << SEPARATOR_ID <<
INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
bool isVis = false;
QList<ActionId> aResAct;
for( int i = 0 ; i < aContextActions.size() ; i++ ){
if( aContextActions[i] != SEPARATOR_ID ){
if( myActionMap.contains(aContextActions[i]) ){
QAction* anAct = myActionMap[aContextActions[i]];
if( anAct->isEnabled() ){
aResAct << aContextActions[i];
isVis = true;
}
}
}
else{
aResAct << SEPARATOR_ID;
}
}
if( !isVis )
return;
QMenu* aMenu = new QMenu(this);
for( int i = 0 ; i < aResAct.size() ; i++ ){
if( aResAct[i] == SEPARATOR_ID ){
aMenu->addSeparator();
}
else{
QAction* anAct = myActionMap[aResAct[i]];
aMenu->insertAction(NULL, anAct);
}
}
aMenu->exec(aGlPoint);
}

View File

@ -1,11 +1,11 @@
#include "CurveCreator_NewPointDlg.h"
#include "CurveCreator_NewSectionDlg.h"
#include "CurveCreator_TreeView.h"
#include "CurveCreator_Widget.h"
#include "CurveCreator.hxx"
#include "CurveCreator_TreeView.h"
#include "QVBoxLayout"
#include "CurveCreator_Curve.hxx"
#include "CurveCreator_CurveEditor.hxx"
#include "CurveCreator.hxx"
#include "CurveCreator_NewPointDlg.h"
#include "CurveCreator_NewSectionDlg.h"
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
@ -19,29 +19,25 @@
#include <QToolBar>
#include <QAction>
#include <QMenu>
#include <QPixmap>
CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
CurveCreator_Curve *theCurve,
Qt::WindowFlags fl) :
QWidget(parent), myNewPointEditor(NULL)
QWidget(parent), myNewPointEditor(NULL), myNewSectionEditor(NULL), myEdit(NULL), myCurve(theCurve)
{
myCurve = theCurve;
if( myCurve )
myEdit = new CurveCreator_CurveEditor( myCurve );
myNewPointEditor = new CurveCreator_NewPointDlg(myCurve->getDimension(), this);
CurveCreator::Dimension aDim = CurveCreator::Dim3d;
if( myCurve )
aDim = myCurve->getDimension();
myNewPointEditor = new CurveCreator_NewPointDlg(aDim, this);
connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()));
myNewSectionEditor = new CurveCreator_NewSectionDlg(this);
connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()));
/* QHBoxLayout* aNameLayout = new QHBoxLayout();
QLabel* aNameLabel = new QLabel(tr("CURVE_NAME_TLT"), this);
aNameLayout->addWidget(aNameLabel);
QLineEdit* aNameEdit = new QLineEdit(this);
aNameLayout->addWidget(aNameEdit); */
QGroupBox* aSectionGroup = new QGroupBox(tr("SECTION_GROUP_TLT"),this);
QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
@ -51,81 +47,113 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
// QToolButton* anUndoBtn = new QToolButton(aTB);
QPixmap anUndoImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoImage, tr("UNDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
/* QPixmap anUndoPixmap = QPixmap(tr(":images/ICON_UNDO"));
QPixmap aRedoPixmap = QPixmap(tr(":images/ICON_REDO"));
QPixmap aNewSectionPixmap = QPixmap(tr(":images/ICON_NEW_SECTION"));
QPixmap aNewPointPixmap = QPixmap(tr(":images/ICON_NEW_POINT"));
QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
QPixmap aRemovePixmap = QPixmap(tr(":images/ICON_REMOVE"));
QPixmap aJoinPixmap = QPixmap(tr(":images/ICON_JOIN"));
QPixmap aStepUpPixmap = QPixmap(tr(":images/ICON_STEP_UP"));
QPixmap aStepDownPixmap = QPixmap(tr(":images/ICON_STEP_DOWN"));*/
QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
aTB->addAction(anAct);
QPixmap aRedoImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_REDO")));
anAct = createAction( REDO_ID, tr("REDO"), aRedoImage, tr("REDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
aTB->addAction(anAct);
aTB->addSeparator();
QPixmap aNewSectImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectImage, tr("NEW_SECTION_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_N) );
anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_N) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
aTB->addAction(anAct);
anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), QPixmap(), tr("INSERT_SECTION_BEFORE_TLT"),
anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), QPixmap(),
tr("INSERT_SECTION_BEFORE_TLT"),
QKeySequence(Qt::ControlModifier | Qt::Key_Insert ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionBefore()) );
anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), QPixmap(), tr("INSERT_SECTION_AFTER_TLT"),
anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), QPixmap(),
tr("INSERT_SECTION_AFTER_TLT"),
QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Insert ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionAfter()) );
QPixmap aNewPointImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
anAct = createAction( NEW_POINT_ID, tr("NEW_POINT"), aNewPointImage, tr("NEW_POINT_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_P) );
anAct = createAction( NEW_POINT_ID, tr("NEW_POINT"), aNewPointPixmap, tr("NEW_POINT_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_P) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onNewPoint()) );
aTB->addAction(anAct);
aTB->addSeparator();
anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), QPixmap(), tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) );
anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), QPixmap(),
tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointBefore()) );
anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), QPixmap(), tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) );
anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), QPixmap(),
tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointAfter()) );
anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_W) );
anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_W) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(), tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
QPixmap aPolylineImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), aPolylineImage, tr("SET_POLYLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_E) );
anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
aPolylinePixmap, tr("SET_POLYLINE_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_E) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
QPixmap aSplineImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplineImage, tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
QPixmap aRemoveImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemoveImage, tr("REMOVE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
aTB->addAction(anAct);
aTB->addSeparator();
QPixmap aJoinImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
anAct = createAction( JOIN_ID, tr("JOIN"), aJoinImage, tr("JOIN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
aTB->addAction(anAct);
aTB->addSeparator();
QPixmap aStepUpImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
anAct = createAction( UP_ID, tr("STEP_UP"), aStepUpImage, tr("STEP_UP_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Up ) );
anAct = createAction( UP_ID, tr("STEP_UP"), aStepUpPixmap, tr("STEP_UP_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Up ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveUp()) );
aTB->addAction(anAct);
QPixmap aStepDownImage(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
anAct = createAction( DOWN_ID, tr("STEP_DOWN"), aStepDownImage, tr("STEP_DOWN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Down ) );
anAct = createAction( DOWN_ID, tr("STEP_DOWN"), aStepDownPixmap, tr("STEP_DOWN"),
QKeySequence(Qt::ControlModifier|Qt::Key_Down ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveDown()) );
aTB->addAction(anAct);
anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
QVBoxLayout* aSectLayout = new QVBoxLayout();
@ -139,9 +167,24 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
onSelectionChanged();
}
void CurveCreator_Widget::setCurve( CurveCreator_Curve* theCurve )
{
if( myEdit != NULL ){
delete myEdit;
myEdit = NULL;
}
myCurve = theCurve;
mySectionView->setCurve(myCurve);
if( myCurve != NULL ){
myEdit = new CurveCreator_CurveEditor(myCurve);
}
onSelectionChanged();
}
void CurveCreator_Widget::onSelectionChanged()
{
QList<ActionId> anEnabledAct;
if( myCurve ){
anEnabledAct << NEW_SECTION_ID;
int aSectCnt = myCurve->getNbPoints();
if( aSectCnt > 0 )
@ -190,12 +233,13 @@ void CurveCreator_Widget::onSelectionChanged()
if( aSelObjsCnt > 0 ){
anEnabledAct << REMOVE_ID;
}
if( myCurve->getNbSections() > 0 ){
if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
anEnabledAct << REMOVE_ALL_ID;
}
if( myCurve->getNbSections() > 1 ){
anEnabledAct << JOIN_ALL_ID;
}
}
QList<ActionId> anIds = myActionMap.keys();
for( int i = 0 ; i < anIds.size() ; i++ ){
if( myActionMap.contains(anIds[i]) ){
@ -211,6 +255,8 @@ void CurveCreator_Widget::onSelectionChanged()
void CurveCreator_Widget::onNewPoint()
{
if( !myEdit )
return;
mySection= -1;
myPointNum = -1;
QList<int> aSelSection = mySectionView->getSelectedSections();
@ -235,6 +281,7 @@ void CurveCreator_Widget::onNewPoint()
myNewPointEditor->clear();
myNewPointEditor->setEditMode(false);
myNewPointEditor->setSectionName(aSectName);
myNewPointEditor->setDimension(myCurve->getDimension());
if( myNewPointEditor->exec() == QDialog::Accepted ){
onAddNewPoint();
}
@ -242,15 +289,20 @@ void CurveCreator_Widget::onNewPoint()
void CurveCreator_Widget::onAddNewPoint()
{
if( !myEdit )
return;
CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
myEdit->insertPoints(aCoords, mySection, myPointNum );
mySectionView->pointsAdded( mySection, myPointNum );
myNewPointEditor->clear();
myPointNum++;
onSelectionChanged();
}
void CurveCreator_Widget::onNewSection()
{
if( !myEdit )
return;
myNewSectionEditor->clear();
myNewSectionEditor->setEditMode(false);
QString aSectName = QString( myCurve->getUnicSectionName().c_str() );
@ -262,6 +314,8 @@ void CurveCreator_Widget::onNewSection()
void CurveCreator_Widget::onAddNewSection()
{
if( !myEdit )
return;
CurveCreator::Coordinates aCoords;
myEdit->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
myNewSectionEditor->isClosed(), aCoords );
@ -269,11 +323,11 @@ void CurveCreator_Widget::onAddNewSection()
QString aNewName = QString(myCurve->getUnicSectionName().c_str());
myNewSectionEditor->setSectionName(aNewName);
mySection++;
onSelectionChanged();
}
QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName,
const QPixmap& theImage, const QString& theToolTip,
const QKeySequence& theShortcut )
QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
const QString& theToolTip, const QKeySequence& theShortcut )
{
QAction* anAct = new QAction(theName,this);
if( !theImage.isNull() ){
@ -294,6 +348,8 @@ QAction* CurveCreator_Widget::getAction(ActionId theId)
void CurveCreator_Widget::onEditSection( int theSection )
{
if( !myEdit )
return;
mySection = theSection;
QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
bool isClosed = myCurve->isClosed(theSection);
@ -313,11 +369,14 @@ void CurveCreator_Widget::onEditSection( int theSection )
void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
{
if( !myNewPointEditor ){
}
if( !myNewPointEditor )
return;
if( !myEdit )
return;
QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
myNewPointEditor->setEditMode(true);
myNewPointEditor->setSectionName(aSectName);
myNewPointEditor->setDimension( myCurve->getDimension() );
CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
myNewPointEditor->setCoordinates(aCoords);
if( myNewPointEditor->exec() == QDialog::Accepted ){
@ -329,6 +388,8 @@ void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
void CurveCreator_Widget::onJoin()
{
if( !myEdit )
return;
QList<int> aSections = mySectionView->getSelectedSections();
if( aSections.size() == 0 ){
return;
@ -347,6 +408,8 @@ void CurveCreator_Widget::onJoin()
void CurveCreator_Widget::onRemove()
{
if( !myEdit )
return;
QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
int aCurrSect=-1;
int aRemoveCnt = 0;
@ -371,6 +434,8 @@ void CurveCreator_Widget::onRemove()
void CurveCreator_Widget::onMoveUp()
{
if( !myEdit )
return;
if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
//Move sections
QList<int> aSections = mySectionView->getSelectedSections();
@ -394,6 +459,8 @@ void CurveCreator_Widget::onMoveUp()
void CurveCreator_Widget::onMoveDown()
{
if( !myEdit )
return;
if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
//Move sections
QList<int> aSections = mySectionView->getSelectedSections();
@ -417,6 +484,8 @@ void CurveCreator_Widget::onMoveDown()
void CurveCreator_Widget::onClearAll()
{
if( !myEdit )
return;
myEdit->clear();
mySectionView->reset();
onSelectionChanged();
@ -424,6 +493,8 @@ void CurveCreator_Widget::onClearAll()
void CurveCreator_Widget::onJoinAll()
{
if( !myEdit )
return;
myEdit->join();
mySectionView->reset();
onSelectionChanged();
@ -456,6 +527,8 @@ void CurveCreator_Widget::onUndoSettings()
void CurveCreator_Widget::onSetSpline()
{
if( !myEdit )
return;
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::BSpline, aSelSections[i]);
@ -465,6 +538,8 @@ void CurveCreator_Widget::onSetSpline()
void CurveCreator_Widget::onSetPolyline()
{
if( !myEdit )
return;
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::Polyline, aSelSections[i]);
@ -474,6 +549,8 @@ void CurveCreator_Widget::onSetPolyline()
void CurveCreator_Widget::onCloseSections()
{
if( !myEdit )
return;
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(true, aSelSections[i]);
@ -483,6 +560,8 @@ void CurveCreator_Widget::onCloseSections()
void CurveCreator_Widget::onUncloseSections()
{
if( !myEdit )
return;
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(false, aSelSections[i]);

View File

@ -22,6 +22,8 @@ public:
CurveCreator_Curve *theCurve,
Qt::WindowFlags fl=0 );
void setCurve( CurveCreator_Curve* theCurve );
signals:
public slots: