-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added undo command classes for point cloud editing
- Loading branch information
Showing
7 changed files
with
202 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*************************************************************************** | ||
qgspointcloudlayerundocommand.cpp | ||
--------------------- | ||
begin : January 2025 | ||
copyright : (C) 2025 by Stefanos Natsis | ||
email : uclaros at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgspointcloudlayerundocommand.h" | ||
#include "qgslazdecoder.h" | ||
|
||
|
||
QgsPointCloudLayerUndoCommand::QgsPointCloudLayerUndoCommand( QgsPointCloudIndex index ) | ||
: mIndex( index ) | ||
{} | ||
|
||
QgsPointCloudLayerUndoCommandChangeAttribute::QgsPointCloudLayerUndoCommandChangeAttribute( QgsPointCloudIndex index, const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value ) | ||
: QgsPointCloudLayerUndoCommand( index ) | ||
, mNode( n ) | ||
, mAttribute( attribute ) | ||
, mNewValue( value ) | ||
{ | ||
const QgsPointCloudAttributeCollection allAttributes = mIndex.attributes(); | ||
QgsPointCloudRequest req; | ||
req.setAttributes( allAttributes ); | ||
std::unique_ptr<QgsPointCloudBlock> block = mIndex.nodeData( n, req ); | ||
const char *ptr = block->data(); | ||
block->attributes().find( attribute.name(), mAttributeOffset ); | ||
const int size = block->pointRecordSize(); | ||
for ( const int point : points ) | ||
{ | ||
const int offset = point * size + mAttributeOffset; | ||
const double oldValue = attribute.convertValueToDouble( ptr + offset ); | ||
mPoints.append( qMakePair( point, oldValue ) ); | ||
} | ||
} | ||
|
||
void QgsPointCloudLayerUndoCommandChangeAttribute::undo() | ||
{ | ||
undoRedoPrivate( true ); | ||
} | ||
|
||
void QgsPointCloudLayerUndoCommandChangeAttribute::redo() | ||
{ | ||
undoRedoPrivate( false ); | ||
} | ||
|
||
void QgsPointCloudLayerUndoCommandChangeAttribute::undoRedoPrivate( bool isUndo ) | ||
{ | ||
const QgsPointCloudAttributeCollection allAttributes = mIndex.attributes(); | ||
|
||
QgsPointCloudRequest req; | ||
req.setAttributes( allAttributes ); | ||
|
||
std::unique_ptr<QgsPointCloudBlock> block = mIndex.nodeData( mNode, req ); | ||
const int count = block->pointCount(); | ||
const int recordSize = block->pointRecordSize(); | ||
|
||
// copy data | ||
QByteArray data( block->data(), count * recordSize ); | ||
|
||
char *ptr = data.data(); | ||
|
||
for ( const auto &pair : std::as_const( mPoints ) ) | ||
{ | ||
// replace attribute for selected point | ||
const double value = isUndo ? pair.second : mNewValue; | ||
lazStoreDoubleToStream( ptr, pair.first * recordSize + mAttributeOffset, mAttribute.type(), value ); | ||
} | ||
|
||
mIndex.updateNodeData( {{mNode, data}} );; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgspointcloudlayerundocommand.h | ||
--------------------- | ||
begin : January 2025 | ||
copyright : (C) 2025 by Stefanos Natsis | ||
email : uclaros at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSPOINTCLOUDLAYERUNDOCOMMAND_H | ||
#define QGSPOINTCLOUDLAYERUNDOCOMMAND_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgspointcloudindex.h" | ||
#include "qgspointcloudattribute.h" | ||
|
||
#include <QUndoCommand> | ||
|
||
class CORE_EXPORT QgsPointCloudLayerUndoCommand : public QUndoCommand | ||
{ | ||
public: | ||
QgsPointCloudLayerUndoCommand( QgsPointCloudIndex index ); | ||
|
||
protected: | ||
QgsPointCloudIndex mIndex; | ||
}; | ||
|
||
class CORE_EXPORT QgsPointCloudLayerUndoCommandChangeAttribute : public QgsPointCloudLayerUndoCommand | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor for QgsPointCloudLayerUndoCommandChangeAttribute | ||
* \param buffer associated edit buffer | ||
* \param f feature to add to layer | ||
*/ | ||
QgsPointCloudLayerUndoCommandChangeAttribute( QgsPointCloudIndex index, const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value ); | ||
|
||
void undo() override; | ||
void redo() override; | ||
|
||
private: | ||
void undoRedoPrivate( bool isUndo ); | ||
|
||
QgsPointCloudNodeId mNode; | ||
QVector< QPair< int, double > > mPoints; // contains pairs of (point number, old value) | ||
QgsPointCloudAttribute mAttribute; | ||
int mAttributeOffset; | ||
double mNewValue; | ||
}; | ||
#endif // QGSPOINTCLOUDLAYERUNDOCOMMAND_H |
Oops, something went wrong.