mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-28 03:40:54 +00:00
Changed: #1302 Added save/saveAs action for primitive item.
This commit is contained in:
parent
6da400630b
commit
a24daa7c0a
5 changed files with 127 additions and 5 deletions
|
@ -197,7 +197,7 @@ void PrimitivesView::save()
|
||||||
QModelIndex index = indexList.first();
|
QModelIndex index = indexList.first();
|
||||||
|
|
||||||
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
||||||
|
|
||||||
if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool())
|
if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool())
|
||||||
{
|
{
|
||||||
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString()))
|
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString()))
|
||||||
|
@ -214,8 +214,8 @@ void PrimitivesView::saveAs()
|
||||||
nlassert(m_primitivesTreeModel);
|
nlassert(m_primitivesTreeModel);
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(this,
|
QString fileName = QFileDialog::getSaveFileName(this,
|
||||||
tr("Save NeL Ligo primitive file"), m_lastDir,
|
tr("Save NeL Ligo primitive file"), m_lastDir,
|
||||||
tr("NeL Ligo primitive file (*.primitive)"));
|
tr("NeL Ligo primitive file (*.primitive)"));
|
||||||
|
|
||||||
setCursor(Qt::WaitCursor);
|
setCursor(Qt::WaitCursor);
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
|
@ -224,7 +224,7 @@ void PrimitivesView::saveAs()
|
||||||
QModelIndex index = indexList.first();
|
QModelIndex index = indexList.first();
|
||||||
|
|
||||||
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
||||||
|
|
||||||
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString()))
|
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString()))
|
||||||
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName));
|
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName));
|
||||||
else
|
else
|
||||||
|
|
|
@ -121,7 +121,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
||||||
|
|
||||||
for (int i = 0; i < sizeVec; ++i)
|
for (int i = 0; i < sizeVec; ++i)
|
||||||
{
|
{
|
||||||
polygon << QPointF(vec->x, -vec->y + cellSize);
|
polygon << QPointF(vec->x, cellSize - vec->y);
|
||||||
++vec;
|
++vec;
|
||||||
}
|
}
|
||||||
item = scene->addWorldItemZone(polygon);
|
item = scene->addWorldItemZone(polygon);
|
||||||
|
@ -216,6 +216,49 @@ QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateGraphicsData(AbstractWorldItem *item)
|
||||||
|
{
|
||||||
|
float cellSize = Utils::ligoConfig()->CellSize;
|
||||||
|
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
|
||||||
|
PrimitiveNode *primitiveNode = static_cast<PrimitiveNode *>(node);
|
||||||
|
if (primitiveNode != 0)
|
||||||
|
{
|
||||||
|
NLLIGO::IPrimitive *primitive = primitiveNode->primitive();
|
||||||
|
|
||||||
|
std::vector<NLLIGO::CPrimVector> vPoints;
|
||||||
|
QPolygonF polygon = item->polygon();
|
||||||
|
polygon.translate(item->pos());
|
||||||
|
|
||||||
|
for (int i = 0; i < polygon.size(); ++i)
|
||||||
|
{
|
||||||
|
NLMISC::CVector vec(polygon.at(i).x(), cellSize - polygon.at(i).y(), 0.0);
|
||||||
|
vPoints.push_back(NLLIGO::CPrimVector(vec));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (primitiveNode->primitiveClass()->Type)
|
||||||
|
{
|
||||||
|
case NLLIGO::CPrimitiveClass::Point:
|
||||||
|
{
|
||||||
|
NLLIGO::CPrimPoint *point = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
||||||
|
point->Point = vPoints.front();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLLIGO::CPrimitiveClass::Path:
|
||||||
|
{
|
||||||
|
NLLIGO::CPrimPath *path = static_cast<NLLIGO::CPrimPath *>(primitive);
|
||||||
|
path->VPoints = vPoints;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NLLIGO::CPrimitiveClass::Zone:
|
||||||
|
{
|
||||||
|
NLLIGO::CPrimZone *zone = static_cast<NLLIGO::CPrimZone *>(primitive);
|
||||||
|
zone->VPoints = vPoints;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
|
CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent),
|
: QUndoCommand(parent),
|
||||||
m_fileName(fileName),
|
m_fileName(fileName),
|
||||||
|
@ -451,6 +494,7 @@ void MoveWorldItemsCommand::undo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->moveBy(-m_offset.x(), -m_offset.y());
|
item->moveBy(-m_offset.x(), -m_offset.y());
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
@ -466,9 +510,20 @@ void MoveWorldItemsCommand::redo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->moveBy(m_offset.x(), m_offset.y());
|
item->moveBy(m_offset.x(), m_offset.y());
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
||||||
|
{
|
||||||
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
updateGraphicsData(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_firstRun = false;
|
m_firstRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,6 +553,7 @@ void RotateWorldItemsCommand::undo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->rotateOn(m_pivot, -m_angle);
|
item->rotateOn(m_pivot, -m_angle);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
@ -513,9 +569,20 @@ void RotateWorldItemsCommand::redo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->rotateOn(m_pivot, m_angle);
|
item->rotateOn(m_pivot, m_angle);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
||||||
|
{
|
||||||
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
updateGraphicsData(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_firstRun = false;
|
m_firstRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,6 +613,7 @@ void ScaleWorldItemsCommand::undo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->scaleOn(m_pivot, m_invertFactor);
|
item->scaleOn(m_pivot, m_invertFactor);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
@ -561,9 +629,20 @@ void ScaleWorldItemsCommand::redo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->scaleOn(m_pivot, m_factor);
|
item->scaleOn(m_pivot, m_factor);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
||||||
|
{
|
||||||
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
updateGraphicsData(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_firstRun = false;
|
m_firstRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,6 +671,7 @@ void TurnWorldItemsCommand::undo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->turnOn(-m_angle);
|
item->turnOn(-m_angle);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
@ -607,9 +687,19 @@ void TurnWorldItemsCommand::redo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->turnOn(m_angle);
|
item->turnOn(m_angle);
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
||||||
|
{
|
||||||
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
updateGraphicsData(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_firstRun = false;
|
m_firstRun = false;
|
||||||
}
|
}
|
||||||
|
@ -642,6 +732,7 @@ void ShapeWorldItemsCommand::undo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->setPolygon(m_redoPolygons.at(i));
|
item->setPolygon(m_redoPolygons.at(i));
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
|
@ -659,9 +750,20 @@ void ShapeWorldItemsCommand::redo()
|
||||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
item->setPolygon(m_undoPolygons.at(i));
|
item->setPolygon(m_undoPolygons.at(i));
|
||||||
|
updateGraphicsData(item);
|
||||||
}
|
}
|
||||||
m_scene->setEnabledEditPoints(pointsMode);
|
m_scene->setEnabledEditPoints(pointsMode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
||||||
|
{
|
||||||
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||||
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
updateGraphicsData(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_firstRun = false;
|
m_firstRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ class ZoneBuilderBase;
|
||||||
namespace WorldEditor
|
namespace WorldEditor
|
||||||
{
|
{
|
||||||
class WorldEditorScene;
|
class WorldEditorScene;
|
||||||
|
class AbstractWorldItem;
|
||||||
|
|
||||||
// Auxiliary operations
|
// Auxiliary operations
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ QList<Path> graphicsItemsToPaths(const QList<QGraphicsItem *> &items, Primitives
|
||||||
|
|
||||||
QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items);
|
QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items);
|
||||||
|
|
||||||
|
void updateGraphicsData(AbstractWorldItem *item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class CreateWorldCommand
|
@class CreateWorldCommand
|
||||||
@brief
|
@brief
|
||||||
|
|
|
@ -182,6 +182,17 @@ void WorldItemPoint::setColor(const QColor &color)
|
||||||
m_brush.setColor(color);
|
m_brush.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldItemPoint::setPolygon(const QPolygonF &polygon)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QPolygonF WorldItemPoint::polygon() const
|
||||||
|
{
|
||||||
|
QPolygonF polygon;
|
||||||
|
polygon << QPointF(0, 0);
|
||||||
|
return polygon;
|
||||||
|
}
|
||||||
|
|
||||||
void WorldItemPoint::createCircle()
|
void WorldItemPoint::createCircle()
|
||||||
{
|
{
|
||||||
if (m_radius != 0)
|
if (m_radius != 0)
|
||||||
|
@ -339,6 +350,7 @@ void WorldItemPath::moveSubPoint(WorldItemSubPoint *subPoint)
|
||||||
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2);
|
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2);
|
||||||
|
|
||||||
m_polygon = polygon;
|
m_polygon = polygon;
|
||||||
|
setShapeChanged(true);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +393,7 @@ void WorldItemPath::addSubPoint(WorldItemSubPoint *subPoint)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setShapeChanged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
|
bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
|
||||||
|
@ -427,6 +440,7 @@ bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
|
||||||
subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2);
|
subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2);
|
||||||
m_listLines.push_back(newLineItem);
|
m_listLines.push_back(newLineItem);
|
||||||
subPoint->setFlag(ItemSendsScenePositionChanges, false);
|
subPoint->setFlag(ItemSendsScenePositionChanges, false);
|
||||||
|
setShapeChanged(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,9 @@ public:
|
||||||
virtual void setColor(const QColor &color);
|
virtual void setColor(const QColor &color);
|
||||||
virtual void setEnabledSubPoints(bool enabled) {}
|
virtual void setEnabledSubPoints(bool enabled) {}
|
||||||
|
|
||||||
|
virtual void setPolygon(const QPolygonF &polygon);
|
||||||
|
virtual QPolygonF polygon() const;
|
||||||
|
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const;
|
||||||
virtual QPainterPath shape() const;
|
virtual QPainterPath shape() const;
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
Loading…
Reference in a new issue