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_Curve.hxx>
#include <CurveCreator_Section.hxx> #include <CurveCreator_Section.hxx>
#include <CurveCreator_Listener.hxx>
#include <stdio.h> #include <stdio.h>
@ -38,7 +39,8 @@
CurveCreator_Curve::CurveCreator_Curve CurveCreator_Curve::CurveCreator_Curve
(const CurveCreator::Dimension theDimension) (const CurveCreator::Dimension theDimension)
: myIsLocked (false), : myIsLocked (false),
myDimension (theDimension) myDimension (theDimension),
myListener(NULL)
{ {
} }
@ -163,8 +165,14 @@ void CurveCreator_Curve::setType
for (; i < aNbSections; i++) { for (; i < aNbSections; i++) {
mySections[i]->myType = theType; mySections[i]->myType = theType;
} }
if( myListener )
myListener->curveChanged();
} else { } 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(), aSection->myPoints.insert(aSection->myPoints.end(),
thePoints.begin(), thePoints.end()); thePoints.begin(), thePoints.end());
if( myListener )
myListener->pointInserted( theISection, -1 );
} }
//======================================================================= //=======================================================================
@ -203,6 +213,8 @@ void CurveCreator_Curve::addSection
aSection->myIsClosed = theIsClosed; aSection->myIsClosed = theIsClosed;
aSection->myPoints = thePoints; aSection->myPoints = thePoints;
mySections.push_back(aSection); mySections.push_back(aSection);
if( myListener )
myListener->sectionAdded( -1 );
} }
//======================================================================= //=======================================================================
@ -220,6 +232,7 @@ void CurveCreator_Curve::removeSection(const int theISection)
delete *anIterRm; delete *anIterRm;
mySections.erase(anIterRm); mySections.erase(anIterRm);
} }
myListener->sectionRemoved(theISection);
} }
//======================================================================= //=======================================================================
@ -240,6 +253,8 @@ void CurveCreator_Curve::insertPoints
aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt), aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt),
thePoints.begin(), thePoints.end()); 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.end() : anIterBegin + toICoord(theNbPoints));
aSection->myPoints.erase(anIterBegin, anIterEnd); aSection->myPoints.erase(anIterBegin, anIterEnd);
myListener->pointRemoved(theISection, theIPnt, theNbPoints );
} }
//======================================================================= //=======================================================================
@ -286,6 +302,8 @@ void CurveCreator_Curve::clear()
} }
mySections.clear(); mySections.clear();
if( myListener )
myListener->curveChanged();
} }
//======================================================================= //=======================================================================
@ -304,6 +322,9 @@ void CurveCreator_Curve::setCoordinates
for (i = 0; i < myDimension; i++) { for (i = 0; i < myDimension; i++) {
aSection->myPoints.at(toICoord(theIPnt) + i) = theCoords[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++) { for (i = 0; i < aSize; i++) {
mySections[i]->myIsClosed = theIsClosed; mySections[i]->myIsClosed = theIsClosed;
if( myListener ){
myListener->sectionClosed( theISection, theIsClosed );
}
} }
} else { } else {
mySections.at(theISection)->myIsClosed = theIsClosed; 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); CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
aSection1->myPoints.insert(aSection1->myPoints.end(), aSection1->myPoints.insert(aSection1->myPoints.end(),
aSection2->myPoints.begin(), aSection2->myPoints.end()); aSection2->myPoints.begin(), aSection2->myPoints.end());
removeSection(theISectionFrom); removeSection(theISectionFrom);
if( myListener )
myListener->curveChanged();
} }
} }
@ -396,6 +425,8 @@ void CurveCreator_Curve::join()
// Just erace section pointers as they were deleted before. // Just erace section pointers as they were deleted before.
mySections.erase(mySections.begin() + 1, mySections.end()); mySections.erase(mySections.begin() + 1, mySections.end());
if( myListener )
myListener->curveChanged();
} }
} }
@ -428,3 +459,21 @@ std::string CurveCreator_Curve::getUnicSectionName()
} }
return ""; 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> #include <QString>
class CurveCreator_Section; class CurveCreator_Section;
class CurveCreator_Listener;
/** /**
* The CurveCreator_Curve object is represented as one or more sets of * The CurveCreator_Curve object is represented as one or more sets of
@ -95,6 +95,17 @@ public:
* Return unic section name * Return unic section name
*/ */
std::string getUnicSectionName(); std::string getUnicSectionName();
/**
* Set curve creator listener object
*/
void setListener( CurveCreator_Listener* myWatcher );
/**
* Remove curve creator listener object
*/
void removeListener();
protected: protected:
/** Set type of the specified section (or all sections /** Set type of the specified section (or all sections
@ -177,6 +188,7 @@ protected:
bool myIsLocked; bool myIsLocked;
Sections mySections; //!< curve data Sections mySections; //!< curve data
CurveCreator::Dimension myDimension; //!< curve dimension CurveCreator::Dimension myDimension; //!< curve dimension
CurveCreator_Listener* myListener; //!< listener
friend class CurveCreator_CurveEditor; friend class CurveCreator_CurveEditor;
friend class CurveCreator_Operation; friend class CurveCreator_Operation;

View File

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

View File

@ -309,6 +309,40 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
return isOK; 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 // function: init
// purpose: // purpose:
@ -330,10 +364,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) { if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) {
// Construct undo for different commands. // Construct undo for different commands.
switch (theType) { switch (theType) {
case CurveCreator_Operation::AddSection:
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1);
break;
case CurveCreator_Operation::InsertPoints: case CurveCreator_Operation::InsertPoints:
{ {
const CurveCreator::Dimension aDim = theCurve->getDimension(); const CurveCreator::Dimension aDim = theCurve->getDimension();
@ -375,6 +405,30 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
return isOK; 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 // function: applyUndo
// purpose: // purpose:

View File

@ -125,7 +125,6 @@ public:
* CurveCreator::Coordinates parameter and two integer parameters. * CurveCreator::Coordinates parameter and two integer parameters.
* It is applicable to the following operations: * It is applicable to the following operations:
* <UL> * <UL>
* <LI>AddSection</LI>
* <LI>InsertPoints</LI> * <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI> * <LI>SetCoordinates</LI>
* </UL> * </UL>
@ -136,6 +135,34 @@ public:
const int theIntParam1, const int theIntParam1,
const int theIntParam2); 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. * 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> #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), myDim(theDim)
{ {
QGridLayout* aCoordLay = new QGridLayout(); QGridLayout* aCoordLay = new QGridLayout();
@ -98,7 +98,7 @@ CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const
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( myDim == CurveCreator::Dim3d ){
double aZ = myZ->value(); double aZ = myZ->value();
aCoords.push_back(aZ); aCoords.push_back(aZ);
} }

View File

@ -208,6 +208,72 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
return isOK; 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 // function: apply
// purpose: // purpose:
@ -271,15 +337,26 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
case CurveCreator_Operation::AddSection: case CurveCreator_Operation::AddSection:
{ {
const CurveCreator::Type aType = (CurveCreator::Type) pInt[0]; const CurveCreator::Type aType = (CurveCreator::Type) pInt[0];
std::string aName = std::string((char*)&pInt[2]);
CurveCreator::Coordinates aCoords; CurveCreator::Coordinates aCoords;
getCoords(&pInt[2], aCoords); char* aPtr = ((char*)&pInt[2]);
theCurve->addSection(std::string(""), aType, (pInt[1] != 0), aCoords); aPtr += (aName.length()) + 1;
getCoords((int*)aPtr, aCoords);
theCurve->addSection(aName, aType, (pInt[1] != 0), aCoords);
} }
break; break;
case CurveCreator_Operation::RemoveSection: case CurveCreator_Operation::RemoveSection:
theCurve->removeSection(pInt[0]); theCurve->removeSection(pInt[0]);
break; break;
case CurveCreator_Operation::RenameSection:
{
std::string aName = std::string((char*)&pInt[1]);
theCurve->setName(aName, pInt[0]);
}
break;
default: default:
break; break;
} }

View File

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

View File

@ -24,7 +24,11 @@ public:
void setCurve( CurveCreator_Curve* theCurve ); void setCurve( CurveCreator_Curve* theCurve );
QList<int> getSelectedSections();
QList< QPair< int, int > > getSelectedPoints();
signals: signals:
void selectionChanged();
public slots: public slots:
@ -50,6 +54,8 @@ protected slots:
void onUncloseSections(); void onUncloseSections();
void onInsertPointBefore(); void onInsertPointBefore();
void onInsertPointAfter(); void onInsertPointAfter();
void onUndo();
void onRedo();
void onUndoSettings(); void onUndoSettings();
void onContextMenu(QPoint thePoint); void onContextMenu(QPoint thePoint);
protected: protected:
@ -61,6 +67,7 @@ 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);
void updateUndoRedo();
private: private:
QMap<ActionId, QAction*> myActionMap; QMap<ActionId, QAction*> myActionMap;
CurveCreator_Curve* myCurve; CurveCreator_Curve* myCurve;

View File

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