1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "landscape_actions.h"
22 #include "builder_zone.h"
25 #include <nel/misc/debug.h>
29 namespace LandscapeEditor
32 LigoTileCommand::LigoTileCommand(const LigoData
&data
, const ZonePosition
&zonePos
,
33 ZoneBuilder
*zoneBuilder
, LandscapeScene
*scene
,
35 : QUndoCommand(parent
),
36 m_zoneBuilder(zoneBuilder
),
46 m_zoneBuilder
->ligoData(m_oldLigoData
, m_zonePos
);
49 LigoTileCommand::~LigoTileCommand()
53 void LigoTileCommand::undo ()
55 m_zoneBuilder
->setLigoData(m_oldLigoData
, m_zonePos
);
58 void LigoTileCommand::redo ()
60 m_zoneBuilder
->setLigoData(m_newLigoData
, m_zonePos
);
63 UndoScanRegionCommand::UndoScanRegionCommand(bool direction
, ZoneBuilder
*zoneBuilder
, LandscapeScene
*scene
, QUndoCommand
*parent
)
64 : QUndoCommand(parent
),
65 m_direction(direction
),
66 m_zoneBuilder(zoneBuilder
),
71 UndoScanRegionCommand::~UndoScanRegionCommand()
73 m_zonePositionList
.clear();
76 void UndoScanRegionCommand::setScanList(const QList
<ZonePosition
> &zonePositionList
)
78 m_zonePositionList
= zonePositionList
;
81 void UndoScanRegionCommand::undo()
87 void UndoScanRegionCommand::redo()
93 void UndoScanRegionCommand::applyChanges()
95 for (int i
= 0; i
< m_zonePositionList
.size(); ++i
)
96 m_scene
->deleteItemZone(m_zonePositionList
.at(i
));
98 for (int i
= 0; i
< m_zonePositionList
.size(); ++i
)
101 m_zoneBuilder
->ligoData(data
, m_zonePositionList
.at(i
));
102 m_scene
->createItemZone(data
, m_zonePositionList
.at(i
));
106 LigoResizeCommand::LigoResizeCommand(int index
, sint32 newMinX
, sint32 newMaxX
,
107 sint32 newMinY
, sint32 newMaxY
, ZoneBuilder
*zoneBuilder
,
108 QUndoCommand
*parent
)
109 : QUndoCommand(parent
),
110 m_zoneBuilder(zoneBuilder
)
118 // Backup old region zone
119 m_oldZoneRegion
= m_zoneBuilder
->zoneRegion(m_index
)->ligoZoneRegion();
122 LigoResizeCommand::~LigoResizeCommand()
126 void LigoResizeCommand::undo ()
128 // Restore old region zone
129 m_zoneBuilder
->zoneRegion(m_index
)->setLigoZoneRegion(m_oldZoneRegion
);
132 void LigoResizeCommand::redo ()
134 // Get the zone region
135 NLLIGO::CZoneRegion
®ion
= m_zoneBuilder
->zoneRegion(m_index
)->ligoZoneRegion();
138 std::vector
<LigoData
> newZones
;
139 newZones
.resize((1 + m_newMaxX
- m_newMinX
) * (1 + m_newMaxY
- m_newMinY
));
141 sint32 newStride
= 1 + m_newMaxX
- m_newMinX
;
142 sint32 Stride
= 1 + region
.getMaxX() - region
.getMinX();
144 for (j
= m_newMinY
; j
<= m_newMaxY
; ++j
)
145 for (i
= m_newMinX
; i
<= m_newMaxX
; ++i
)
147 // Ref on the new value
148 LigoData
&data
= newZones
[(i
- m_newMinX
) + (j
- m_newMinY
) * newStride
];
150 // In the old array ?
151 if ((i
>= region
.getMinX()) && (i
<= region
.getMaxX()) &&
152 (j
>= region
.getMinY()) && (j
<= region
.getMaxY()))
155 m_zoneBuilder
->ligoData(data
, ZonePosition(i
, j
, m_index
));
158 region
.resize(m_newMinX
, m_newMaxX
, m_newMinY
, m_newMaxY
);
160 for (j
= m_newMinY
; j
<= m_newMaxY
; ++j
)
161 for (i
= m_newMinX
; i
<= m_newMaxX
; ++i
)
163 // Ref on the new value
164 const LigoData
&data
= newZones
[(i
- m_newMinX
) + (j
- m_newMinY
) * newStride
];
166 region
.setName(i
, j
, data
.zoneName
);
167 region
.setPosX(i
, j
, data
.posX
);
168 region
.setPosY(i
, j
, data
.posY
);
169 region
.setRot(i
, j
, data
.rot
);
170 region
.setFlip(i
, j
, data
.flip
);
172 for (k
= 0; k
< 4; k
++)
174 region
.setSharingMatNames(i
, j
, k
, data
.sharingMatNames
[k
]);
175 region
.setSharingCutEdges(i
, j
, k
, data
.sharingCutEdges
[k
]);
180 } /* namespace LandscapeEditor */