CurveCreator was updated

This commit is contained in:
mtn 2013-08-30 14:40:26 +00:00
parent 30060b79f1
commit 1c0d14d5b2
13 changed files with 432 additions and 23 deletions

View File

@ -28,6 +28,7 @@
#include <CurveCreator_Curve.hxx>
#include <CurveCreator_Section.hxx>
#include <CurveCreator_Listener.hxx>
#include <stdio.h>
@ -38,7 +39,8 @@
CurveCreator_Curve::CurveCreator_Curve
(const CurveCreator::Dimension theDimension)
: myIsLocked (false),
myDimension (theDimension)
myDimension (theDimension),
myListener(NULL)
{
}
@ -163,8 +165,14 @@ void CurveCreator_Curve::setType
for (; i < aNbSections; i++) {
mySections[i]->myType = theType;
}
if( myListener )
myListener->curveChanged();
} else {
mySections.at(theISection)->myType = theType;
if( mySections.at(theISection)->myType != theType ){
mySections.at(theISection)->myType = theType;
if( myListener )
myListener->sectionTypeChanged(theISection);
}
}
}
@ -180,6 +188,8 @@ void CurveCreator_Curve::addPoints
aSection->myPoints.insert(aSection->myPoints.end(),
thePoints.begin(), thePoints.end());
if( myListener )
myListener->pointInserted( theISection, -1 );
}
//=======================================================================
@ -203,6 +213,8 @@ void CurveCreator_Curve::addSection
aSection->myIsClosed = theIsClosed;
aSection->myPoints = thePoints;
mySections.push_back(aSection);
if( myListener )
myListener->sectionAdded( -1 );
}
//=======================================================================
@ -220,6 +232,7 @@ void CurveCreator_Curve::removeSection(const int theISection)
delete *anIterRm;
mySections.erase(anIterRm);
}
myListener->sectionRemoved(theISection);
}
//=======================================================================
@ -240,6 +253,8 @@ void CurveCreator_Curve::insertPoints
aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt),
thePoints.begin(), thePoints.end());
if( myListener )
myListener->pointInserted( theISection, theIPnt );
}
}
@ -269,6 +284,7 @@ void CurveCreator_Curve::removePoints(const int theISection,
aSection->myPoints.end() : anIterBegin + toICoord(theNbPoints));
aSection->myPoints.erase(anIterBegin, anIterEnd);
myListener->pointRemoved(theISection, theIPnt, theNbPoints );
}
//=======================================================================
@ -286,6 +302,8 @@ void CurveCreator_Curve::clear()
}
mySections.clear();
if( myListener )
myListener->curveChanged();
}
//=======================================================================
@ -304,6 +322,9 @@ void CurveCreator_Curve::setCoordinates
for (i = 0; i < myDimension; i++) {
aSection->myPoints.at(toICoord(theIPnt) + i) = theCoords[i];
}
if( myListener )
myListener->pointChanged( theISection, theIPnt );
}
}
@ -320,9 +341,15 @@ void CurveCreator_Curve::setClosed(const bool theIsClosed,
for (i = 0; i < aSize; i++) {
mySections[i]->myIsClosed = theIsClosed;
if( myListener ){
myListener->sectionClosed( theISection, theIsClosed );
}
}
} else {
mySections.at(theISection)->myIsClosed = theIsClosed;
if( myListener ){
myListener->sectionClosed( theISection, theIsClosed );
}
}
}
@ -368,9 +395,11 @@ void CurveCreator_Curve::join(const int theISectionTo,
CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
aSection1->myPoints.insert(aSection1->myPoints.end(),
aSection2->myPoints.begin(), aSection2->myPoints.end());
aSection2->myPoints.begin(), aSection2->myPoints.end());
removeSection(theISectionFrom);
if( myListener )
myListener->curveChanged();
}
}
@ -396,6 +425,8 @@ void CurveCreator_Curve::join()
// Just erace section pointers as they were deleted before.
mySections.erase(mySections.begin() + 1, mySections.end());
if( myListener )
myListener->curveChanged();
}
}
@ -428,3 +459,21 @@ std::string CurveCreator_Curve::getUnicSectionName()
}
return "";
}
//=======================================================================
// function: setListener
// purpose: set curve changes listener
//=======================================================================
void CurveCreator_Curve::setListener( CurveCreator_Listener* theListener )
{
myListener = theListener;
}
//=======================================================================
// function: setListener
// purpose: set curve changes listener
//=======================================================================
void CurveCreator_Curve::removeListener()
{
myListener = NULL;
}

View File

@ -36,7 +36,7 @@
#include <QString>
class CurveCreator_Section;
class CurveCreator_Listener;
/**
* The CurveCreator_Curve object is represented as one or more sets of
@ -95,6 +95,17 @@ public:
* Return unic section name
*/
std::string getUnicSectionName();
/**
* Set curve creator listener object
*/
void setListener( CurveCreator_Listener* myWatcher );
/**
* Remove curve creator listener object
*/
void removeListener();
protected:
/** Set type of the specified section (or all sections
@ -177,6 +188,7 @@ protected:
bool myIsLocked;
Sections mySections; //!< curve data
CurveCreator::Dimension myDimension; //!< curve dimension
CurveCreator_Listener* myListener; //!< listener
friend class CurveCreator_CurveEditor;
friend class CurveCreator_Operation;

View File

@ -37,7 +37,8 @@ CurveCreator_CurveEditor::CurveCreator_CurveEditor
: myNbUndos (0),
myNbRedos (0),
myPCurve (thePCurve),
myUndoDepth (-1)
myUndoDepth (-1),
myOpLevel(0)
{
if (myPCurve != NULL) {
if (myPCurve->isLocked()) {
@ -193,6 +194,7 @@ void CurveCreator_CurveEditor::setType(const CurveCreator::Type theType,
const int theISection)
{
if (myPCurve != NULL) {
startOperation();
// Set the difference.
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetType,
@ -201,6 +203,7 @@ void CurveCreator_CurveEditor::setType(const CurveCreator::Type theType,
// Update the curve.
myPCurve->setType(theType, theISection);
finishOperation();
}
}
@ -214,6 +217,7 @@ void CurveCreator_CurveEditor::addPoints
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddPoints,
thePoints, theISection);
@ -221,6 +225,7 @@ void CurveCreator_CurveEditor::addPoints
// Update the curve.
myPCurve->addPoints(thePoints, theISection);
finishOperation();
}
}
@ -235,13 +240,15 @@ void CurveCreator_CurveEditor::addSection
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddSection,
thePoints, theType, theIsClosed);
theName, thePoints, theType, theIsClosed);
}
// Update the curve.
myPCurve->addSection(theName, theType, theIsClosed, thePoints);
finishOperation();
}
}
@ -253,6 +260,7 @@ void CurveCreator_CurveEditor::removeSection(const int theISection)
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemoveSection,
theISection);
@ -260,6 +268,7 @@ void CurveCreator_CurveEditor::removeSection(const int theISection)
// Update the curve.
myPCurve->removeSection(theISection);
finishOperation();
}
}
@ -274,6 +283,7 @@ void CurveCreator_CurveEditor::insertPoints
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::InsertPoints,
thePoints, theISection, theIPnt);
@ -281,6 +291,7 @@ void CurveCreator_CurveEditor::insertPoints
// Update the curve.
myPCurve->insertPoints(thePoints, theISection, theIPnt);
finishOperation();
}
}
@ -292,7 +303,9 @@ void CurveCreator_CurveEditor::movePoint(const int theISection,
const int theOrigIPnt,
const int theNewIPnt )
{
startOperation();
myPCurve->movePoint(theISection, theOrigIPnt, theNewIPnt);
finishOperation();
}
//=======================================================================
@ -306,6 +319,7 @@ void CurveCreator_CurveEditor::removePoints
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemovePoints,
theISection, theIPnt, theNbPoints);
@ -313,6 +327,7 @@ void CurveCreator_CurveEditor::removePoints
// Update the curve.
myPCurve->removePoints(theISection, theIPnt, theNbPoints);
finishOperation();
}
}
@ -323,6 +338,7 @@ void CurveCreator_CurveEditor::removePoints
void CurveCreator_CurveEditor::clear()
{
if (myPCurve != NULL) {
startOperation();
// Set the difference.
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::Clear);
@ -330,6 +346,7 @@ void CurveCreator_CurveEditor::clear()
// Update the curve.
myPCurve->clear();
finishOperation();
}
}
@ -344,6 +361,7 @@ void CurveCreator_CurveEditor::setCoordinates
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetCoordinates,
theCoords, theISection, theIPnt);
@ -351,6 +369,7 @@ void CurveCreator_CurveEditor::setCoordinates
// Update the curve.
myPCurve->setCoordinates(theCoords, theISection, theIPnt);
finishOperation();
}
}
@ -363,6 +382,7 @@ void CurveCreator_CurveEditor::setClosed(const bool theIsClosed,
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetClosed,
theIsClosed, theISection);
@ -370,6 +390,7 @@ void CurveCreator_CurveEditor::setClosed(const bool theIsClosed,
// Update the curve.
myPCurve->setClosed(theIsClosed, theISection);
finishOperation();
}
}
@ -380,7 +401,16 @@ void CurveCreator_CurveEditor::setClosed(const bool theIsClosed,
void CurveCreator_CurveEditor::setName(const std::string& theName,
const int theISection)
{
myPCurve->setName( theName, theISection );
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::RenameSection,
theName, theISection);
}
myPCurve->setName( theName, theISection );
finishOperation();
}
}
//=======================================================================
@ -392,6 +422,7 @@ void CurveCreator_CurveEditor::moveSection(const int theISection,
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::MoveSection,
theISection, theNewIndex);
@ -399,6 +430,7 @@ void CurveCreator_CurveEditor::moveSection(const int theISection,
// Update the curve.
myPCurve->moveSection(theISection, theNewIndex);
finishOperation();
}
}
@ -411,6 +443,7 @@ void CurveCreator_CurveEditor::join(const int theISectionTo,
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join,
theISectionTo, theISectionFrom);
@ -418,6 +451,7 @@ void CurveCreator_CurveEditor::join(const int theISectionTo,
// Update the curve.
myPCurve->join(theISectionTo, theISectionFrom);
finishOperation();
}
}
@ -429,12 +463,14 @@ void CurveCreator_CurveEditor::join()
{
if (myPCurve != NULL) {
// Set the difference.
startOperation();
if (addEmptyDiff()) {
myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join);
}
// Update the curve.
myPCurve->join();
finishOperation();
}
}
@ -469,3 +505,13 @@ bool CurveCreator_CurveEditor::addEmptyDiff()
return isEnabled;
}
void CurveCreator_CurveEditor::startOperation()
{
myOpLevel++;
}
void CurveCreator_CurveEditor::finishOperation()
{
myOpLevel--;
}

View File

@ -146,6 +146,8 @@ public:
//! Join all sections to the single curve
void join();
void startOperation();
void finishOperation();
private:
/** This method updates all undo/redo information required to be updated
@ -162,7 +164,7 @@ private:
ListDiff myListDiffs;
CurveCreator_Curve* myPCurve;
int myUndoDepth;
int myOpLevel;
};
#endif

View File

@ -309,6 +309,40 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
return isOK;
}
//=======================================================================
// function: init
// purpose:
//=======================================================================
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
const std::string& theName,
const CurveCreator::Coordinates &theCoords,
const int theIntParam1,
const int theIntParam2)
{
bool isOK = false;
if (theCurve != NULL) {
clear();
// Set redo.
myPRedo = new CurveCreator_Operation;
if (myPRedo->init(theType, theName, theCoords, theIntParam1, theIntParam2)) {
// Construct undo for different commands.
switch (theType) {
case CurveCreator_Operation::AddSection:
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1);
break;
}
}
}
if( !isOK )
clear();
return isOK;
}
//=======================================================================
// function: init
// purpose:
@ -330,10 +364,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) {
// Construct undo for different commands.
switch (theType) {
case CurveCreator_Operation::AddSection:
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1);
break;
case CurveCreator_Operation::InsertPoints:
{
const CurveCreator::Dimension aDim = theCurve->getDimension();
@ -375,6 +405,30 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
return isOK;
}
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
const std::string &theName,
const int theIntParam1 )
{
bool isOK = false;
myPRedo = new CurveCreator_Operation;
if (myPRedo->init(theType, theName, theIntParam1 )) {
// Construct undo for different commands.
switch (theType) {
case CurveCreator_Operation::RenameSection:
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection,
theCurve->getSectionName(theIntParam1), theIntParam1);
break;
}
}
if( !isOK ){
clear();
}
return isOK;
}
//=======================================================================
// function: applyUndo
// purpose:

View File

@ -125,7 +125,6 @@ public:
* CurveCreator::Coordinates parameter and two integer parameters.
* It is applicable to the following operations:
* <UL>
* <LI>AddSection</LI>
* <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI>
* </UL>
@ -136,6 +135,34 @@ public:
const int theIntParam1,
const int theIntParam2);
/**
* This method initializes the difference with an operation with one
* Name, one CurveCreator::Coordinates parameter and two integer parameters.
* It is applicable to the following operations:
* <UL>
* <LI>AddSection</LI>
* </UL>
*/
bool init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
const std::string& theName,
const CurveCreator::Coordinates &theCoords,
const int theIntParam1,
const int theIntParam2);
/**
* This method initializes the difference with an operation with one
* string and one integer parameters.
* It is applicable to the following operations:
* <UL>
* <LI>RenameSection</LI>
* </UL>
*/
bool init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
const std::string &theName,
const int theIntParam1 );
/**
* This method applies undo operation to theCurve.
*/

View File

@ -0,0 +1,22 @@
#ifndef CURVE_CREATOR_LISTENER_HXX
#define CURVE_CREATOR_LISTENER_HXX
class CurveCreator_Listener
{
public:
CurveCreator_Listener(void){};
virtual ~CurveCreator_Listener(void){};
virtual void pointChanged( int theSection, int thePoint ){}
virtual void pointRemoved( int theSection, int theFirstPoint, int thePointCnt ){}
virtual void pointInserted( int theSection, int theIndx ){}
virtual void sectionClosed( int theSection, bool isClosed ){}
virtual void sectionAdded( int theSection ){}
virtual void sectionRemoved( int theSection ){}
virtual void sectionTypeChanged( int theSection ){}
virtual void curveChanged(){}
};
#endif

View File

@ -11,7 +11,7 @@
#include <QLocale>
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), myDim(theDim)
{
QGridLayout* aCoordLay = new QGridLayout();
@ -98,7 +98,7 @@ CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const
aCoords.push_back(anX);
double anY = myY->value();
aCoords.push_back(anY);
if( myZ->isVisible() ){
if( myDim == CurveCreator::Dim3d ){
double aZ = myZ->value();
aCoords.push_back(aZ);
}

View File

@ -208,6 +208,72 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
return isOK;
}
//=======================================================================
// function: Constructor
// purpose:
//=======================================================================
bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
const std::string& theName,
const CurveCreator::Coordinates &theCoords,
const int theIntParam1,
const int theIntParam2)
{
bool isOK = false;
if (theType == CurveCreator_Operation::AddSection ) {
const int aNbCoords = theCoords.size();
const size_t aSize =
3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord) + theName.length() + 1;
int *pIntData = (int *)allocate(aSize);
*pIntData++ = theIntParam1;
*pIntData++ = theIntParam2;
char* aStrPtr = (char*)pIntData;
if( !theName.empty() ){
strcpy( aStrPtr, theName.c_str() );
aStrPtr += theName.length();
}
else{
*aStrPtr = 0;
}
aStrPtr++;
pIntData = (int*)aStrPtr;
*pIntData++ = aNbCoords;
CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)aStrPtr;
int i = 0;
for (; i < aNbCoords; i++) {
*pRealData++ = theCoords[i];
}
myType = theType;
isOK = true;
}
return isOK;
}
bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
const std::string &theName,
const int theIntParam1 )
{
if (theType == CurveCreator_Operation::RenameSection ) {
size_t aSize = sizeof(theIntParam1) + theName.length() + 1;
int *pIntData = (int *)allocate(aSize);
*pIntData = theIntParam1;
pIntData++;
if( !theName.empty() ){
strcpy( (char*)pIntData, theName.c_str() );
}
else{
*((char*)pIntData) = 0;
}
myType = theType;
return true;
}
return false;
}
//=======================================================================
// function: apply
// purpose:
@ -271,15 +337,26 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
case CurveCreator_Operation::AddSection:
{
const CurveCreator::Type aType = (CurveCreator::Type) pInt[0];
std::string aName = std::string((char*)&pInt[2]);
CurveCreator::Coordinates aCoords;
getCoords(&pInt[2], aCoords);
theCurve->addSection(std::string(""), aType, (pInt[1] != 0), aCoords);
char* aPtr = ((char*)&pInt[2]);
aPtr += (aName.length()) + 1;
getCoords((int*)aPtr, aCoords);
theCurve->addSection(aName, aType, (pInt[1] != 0), aCoords);
}
break;
case CurveCreator_Operation::RemoveSection:
theCurve->removeSection(pInt[0]);
break;
case CurveCreator_Operation::RenameSection:
{
std::string aName = std::string((char*)&pInt[1]);
theCurve->setName(aName, pInt[0]);
}
break;
default:
break;
}

View File

@ -30,6 +30,7 @@
#include <CurveCreator.hxx>
#include <string>
class CurveCreator_Curve;
@ -60,7 +61,7 @@ public:
Join, //!< Method CurveCreator_Curve::join
AddSection, //!< Method CurveCreator_Curve::addSection
RemoveSection, //!< Method CurveCreator_Curve::removeSection
RenameCurve //!< Method CurveCreator_Curve::renameCurve
RenameSection //!< Method CurveCreator_Curve::renameSection
};
/**
@ -145,6 +146,37 @@ public:
bool init(const Type theType, const CurveCreator::Coordinates &theCoords,
const int theIntParam1, const int theIntParam2);
/**
* This method initializes the object with an operation with one
* string, one CurveCreator::Coordinates parameter and two integer parameters.
* It is applicable to the following operations:
* <UL>
* <LI>AddSection</LI>
* <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI>
* </UL>
* @return true in case of success; false otherwise.
*/
bool init(const CurveCreator_Operation::Type theType,
const std::string& theName,
const CurveCreator::Coordinates &theCoords,
const int theIntParam1,
const int theIntParam2);
/**
* This method initializes the object with an operation with one
* string parameter and one integer.
* It is applicable to the following operations:
* <UL>
* <LI>RenameSection</LI>
* </UL>
* @return true in case of success; false otherwise.
*/
bool init(const CurveCreator_Operation::Type theType,
const std::string &theName,
const int theIntParam1 );
/**
* This method applies the current operation to theCurve.
*/

View File

@ -72,10 +72,12 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
aTB->addAction(anAct);
anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
aTB->addAction(anAct);
aTB->addSeparator();
@ -179,6 +181,7 @@ void CurveCreator_Widget::setCurve( CurveCreator_Curve* theCurve )
myEdit = new CurveCreator_CurveEditor(myCurve);
}
onSelectionChanged();
updateUndoRedo();
}
void CurveCreator_Widget::onSelectionChanged()
@ -251,6 +254,7 @@ void CurveCreator_Widget::onSelectionChanged()
}
}
}
emit selectionChanged();
}
void CurveCreator_Widget::onNewPoint()
@ -297,6 +301,7 @@ void CurveCreator_Widget::onAddNewPoint()
myNewPointEditor->clear();
myPointNum++;
onSelectionChanged();
updateUndoRedo();
}
void CurveCreator_Widget::onNewSection()
@ -324,6 +329,7 @@ void CurveCreator_Widget::onAddNewSection()
myNewSectionEditor->setSectionName(aNewName);
mySection++;
onSelectionChanged();
updateUndoRedo();
}
QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
@ -360,10 +366,13 @@ void CurveCreator_Widget::onEditSection( int theSection )
QString aName = myNewSectionEditor->getName();
bool isClosed = myNewSectionEditor->isClosed();
CurveCreator::Type aSectType = myNewSectionEditor->getSectionType();
myEdit->startOperation();
myEdit->setClosed( isClosed, mySection );
myEdit->setName( aName.toStdString(), mySection );
myEdit->setType( aSectType, mySection );
myEdit->finishOperation();
mySectionView->sectionChanged(mySection);
updateUndoRedo();
}
}
@ -383,6 +392,7 @@ void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
aCoords = myNewPointEditor->getCoordinates();
myEdit->setCoordinates(aCoords, theSection, thePoint);
mySectionView->pointDataChanged(theSection, thePoint );
updateUndoRedo();
}
}
@ -396,14 +406,17 @@ void CurveCreator_Widget::onJoin()
}
int aMainSect = aSections[0];
int aMainSectSize = myCurve->getNbPoints(aMainSect);
myEdit->startOperation();
for( int i = 1 ; i < aSections.size() ; i++ ){
int aSectNum = aSections[i] - (i-1);
myEdit->join( aMainSect, aSectNum );
mySectionView->sectionsRemoved( aSectNum );
}
myEdit->finishOperation();
int aNewSectSize = myCurve->getNbPoints(aMainSect);
if( aNewSectSize != aMainSectSize )
mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
updateUndoRedo();
}
void CurveCreator_Widget::onRemove()
@ -413,6 +426,7 @@ void CurveCreator_Widget::onRemove()
QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
int aCurrSect=-1;
int aRemoveCnt = 0;
myEdit->startOperation();
for( int i = 0 ; i < aSelPoints.size() ; i++ ){
if( aCurrSect != aSelPoints[i].first ){
aRemoveCnt = 0;
@ -429,7 +443,9 @@ void CurveCreator_Widget::onRemove()
myEdit->removeSection( aSectNum );
mySectionView->sectionsRemoved( aSectNum );
}
myEdit->finishOperation();
mySectionView->clearSelection();
updateUndoRedo();
}
void CurveCreator_Widget::onMoveUp()
@ -455,6 +471,7 @@ void CurveCreator_Widget::onMoveUp()
mySectionView->pointsSwapped( aSection, aPoint, -1 );
}
}
updateUndoRedo();
}
void CurveCreator_Widget::onMoveDown()
@ -480,6 +497,7 @@ void CurveCreator_Widget::onMoveDown()
mySectionView->pointsSwapped( aSection, aPoint, 1 );
}
}
updateUndoRedo();
}
void CurveCreator_Widget::onClearAll()
@ -489,6 +507,7 @@ void CurveCreator_Widget::onClearAll()
myEdit->clear();
mySectionView->reset();
onSelectionChanged();
updateUndoRedo();
}
void CurveCreator_Widget::onJoinAll()
@ -498,6 +517,7 @@ void CurveCreator_Widget::onJoinAll()
myEdit->join();
mySectionView->reset();
onSelectionChanged();
updateUndoRedo();
}
void CurveCreator_Widget::onInsertSectionBefore()
@ -530,53 +550,103 @@ void CurveCreator_Widget::onSetSpline()
if( !myEdit )
return;
QList<int> aSelSections = mySectionView->getSelectedSections();
myEdit->startOperation();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::BSpline, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
myEdit->finishOperation();
updateUndoRedo();
}
void CurveCreator_Widget::onSetPolyline()
{
if( !myEdit )
return;
myEdit->startOperation();
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setType(CurveCreator::Polyline, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
myEdit->finishOperation();
updateUndoRedo();
}
void CurveCreator_Widget::onCloseSections()
{
if( !myEdit )
return;
myEdit->startOperation();
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(true, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
myEdit->finishOperation();
updateUndoRedo();
}
void CurveCreator_Widget::onUncloseSections()
{
if( !myEdit )
return;
myEdit->startOperation();
QList<int> aSelSections = mySectionView->getSelectedSections();
for( int i = 0 ; i < aSelSections.size() ; i++ ){
myEdit->setClosed(false, aSelSections[i]);
mySectionView->sectionChanged(aSelSections[i]);
}
myEdit->finishOperation();
updateUndoRedo();
}
void CurveCreator_Widget::onUndo()
{
if( !myEdit )
return;
myEdit->undo();
mySectionView->reset();
updateUndoRedo();
}
void CurveCreator_Widget::onRedo()
{
if( !myEdit )
return;
myEdit->redo();
mySectionView->reset();
updateUndoRedo();
}
void CurveCreator_Widget::updateUndoRedo()
{
QAction* anAct = myActionMap[UNDO_ID];
if( anAct != 0 ){
if( myEdit->getNbUndo() != 0 ){
anAct->setEnabled(true);
}
else{
anAct->setDisabled(true);
}
}
anAct = myActionMap[REDO_ID];
if( anAct != 0 ){
if( myEdit->getNbRedo() != 0 ){
anAct->setEnabled(true);
}
else{
anAct->setDisabled(true);
}
}
}
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;
SET_SECTIONS_SPLINE_ID;
QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
bool isVis = false;
QList<ActionId> aResAct;
@ -609,3 +679,13 @@ void CurveCreator_Widget::onContextMenu( QPoint thePoint )
}
aMenu->exec(aGlPoint);
}
QList<int> CurveCreator_Widget::getSelectedSections()
{
return mySectionView->getSelectedSections();
}
QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
{
return mySectionView->getSelectedPoints();
}

View File

@ -24,8 +24,12 @@ public:
void setCurve( CurveCreator_Curve* theCurve );
QList<int> getSelectedSections();
QList< QPair< int, int > > getSelectedPoints();
signals:
void selectionChanged();
public slots:
protected slots:
@ -50,6 +54,8 @@ protected slots:
void onUncloseSections();
void onInsertPointBefore();
void onInsertPointAfter();
void onUndo();
void onRedo();
void onUndoSettings();
void onContextMenu(QPoint thePoint);
protected:
@ -61,6 +67,7 @@ private:
QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
const QString& theToolTip, const QKeySequence& theShortcut );
QAction* getAction(ActionId theId);
void updateUndoRedo();
private:
QMap<ActionId, QAction*> myActionMap;
CurveCreator_Curve* myCurve;

View File

@ -49,7 +49,8 @@ salomeinclude_HEADERS = \
CurveCreator_Diff.hxx \
CurveCreator_Section.hxx \
CurveCreator_Curve.hxx \
CurveCreator_CurveEditor.hxx
CurveCreator_CurveEditor.hxx \
CurveCreator_Listener.hxx
# Compilation options for GUI mode
if GEOM_ENABLE_GUI