Fix node group saving

master
Jeremy Hu 2018-03-20 11:31:05 +08:00
parent a4cdb4e551
commit 4661e2bc94
4 changed files with 39 additions and 5 deletions

View File

@ -31,8 +31,10 @@ int main(int argc, char ** argv)
QCoreApplication::setApplicationName("Dust 3D"); QCoreApplication::setApplicationName("Dust 3D");
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); QFont font;
QApplication::setFont(fixedFont); font.setWeight(QFont::Light);
font.setPointSize(9);
QApplication::setFont(font);
MainWindow mainWindow; MainWindow mainWindow;
mainWindow.showMaximized(); mainWindow.showMaximized();

View File

@ -64,7 +64,7 @@ MainWindow::MainWindow()
QVBoxLayout *modelRightLayout = new QVBoxLayout; QVBoxLayout *modelRightLayout = new QVBoxLayout;
modelRightLayout->addSpacing(20); modelRightLayout->addSpacing(10);
QPushButton *changeTurnaroundButton = new QPushButton(" Change Turnaround "); QPushButton *changeTurnaroundButton = new QPushButton(" Change Turnaround ");
modelRightLayout->addWidget(changeTurnaroundButton); modelRightLayout->addWidget(changeTurnaroundButton);

View File

@ -497,6 +497,7 @@ void SkeletonEditGraphicsView::loadFromXmlStream(QXmlStreamReader &reader)
std::vector<std::map<QString, QString>> pendingNodes; std::vector<std::map<QString, QString>> pendingNodes;
std::vector<std::map<QString, QString>> pendingEdges; std::vector<std::map<QString, QString>> pendingEdges;
std::map<QString, SkeletonEditNodeItem *> addedNodeMapById; std::map<QString, SkeletonEditNodeItem *> addedNodeMapById;
std::map<QString, QGraphicsItemGroup *> addedGroupMapById;
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
@ -523,11 +524,13 @@ void SkeletonEditGraphicsView::loadFromXmlStream(QXmlStreamReader &reader)
} }
} else if (reader.name() == "node") { } else if (reader.name() == "node") {
QString nodeId = reader.attributes().value("id").toString(); QString nodeId = reader.attributes().value("id").toString();
QString nodeGroupId = reader.attributes().value("group").toString();
QString nodeType = reader.attributes().value("type").toString(); QString nodeType = reader.attributes().value("type").toString();
QString nodePairId = reader.attributes().value("pair").toString(); QString nodePairId = reader.attributes().value("pair").toString();
QString nodeRadius = reader.attributes().value("radius").toString(); QString nodeRadius = reader.attributes().value("radius").toString();
std::map<QString, QString> pendingNode; std::map<QString, QString> pendingNode;
pendingNode["id"] = nodeId; pendingNode["id"] = nodeId;
pendingNode["group"] = nodeGroupId;
pendingNode["type"] = nodeType; pendingNode["type"] = nodeType;
pendingNode["pair"] = nodePairId; pendingNode["pair"] = nodePairId;
pendingNode["radius"] = QString("%1").arg(nodeRadius.toFloat() * radiusMul); pendingNode["radius"] = QString("%1").arg(nodeRadius.toFloat() * radiusMul);
@ -554,7 +557,15 @@ void SkeletonEditGraphicsView::loadFromXmlStream(QXmlStreamReader &reader)
float radius = (*pendingNode)["radius"].toFloat(); float radius = (*pendingNode)["radius"].toFloat();
QRectF nodeRect((*pendingNode)["x"].toFloat() - radius, (*pendingNode)["y"].toFloat() - radius, QRectF nodeRect((*pendingNode)["x"].toFloat() - radius, (*pendingNode)["y"].toFloat() - radius,
radius * 2, radius * 2); radius * 2, radius * 2);
addedNodeMapById[(*pendingNode)["id"]] = new SkeletonEditNodeItem(nodeRect); SkeletonEditNodeItem *nodeItem = new SkeletonEditNodeItem(nodeRect);
addedNodeMapById[(*pendingNode)["id"]] = nodeItem;
std::map<QString, QGraphicsItemGroup *>::iterator findGroup = addedGroupMapById.find((*pendingNode)["group"]);
if (findGroup == addedGroupMapById.end()) {
QGraphicsItemGroup *group = new QGraphicsItemGroup;
scene()->addItem(group);
addedGroupMapById[(*pendingNode)["group"]] = group;
}
nodeItem->setGroup(addedGroupMapById[(*pendingNode)["group"]]);
} }
for (size_t i = 0; i < pendingNodes.size(); i++) { for (size_t i = 0; i < pendingNodes.size(); i++) {
@ -570,7 +581,9 @@ void SkeletonEditGraphicsView::loadFromXmlStream(QXmlStreamReader &reader)
for (size_t i = 0; i < pendingEdges.size(); i++) { for (size_t i = 0; i < pendingEdges.size(); i++) {
std::map<QString, QString> *pendingEdge = &pendingEdges[i]; std::map<QString, QString> *pendingEdge = &pendingEdges[i];
SkeletonEditEdgeItem *newEdge = new SkeletonEditEdgeItem(); SkeletonEditEdgeItem *newEdge = new SkeletonEditEdgeItem();
newEdge->setNodes(addedNodeMapById[(*pendingEdge)["from"]], addedNodeMapById[(*pendingEdge)["to"]]); SkeletonEditNodeItem *fromNodeItem = addedNodeMapById[(*pendingEdge)["from"]];
SkeletonEditNodeItem *toNodeItem = addedNodeMapById[(*pendingEdge)["to"]];
newEdge->setNodes(fromNodeItem, toNodeItem);
scene()->addItem(newEdge); scene()->addItem(newEdge);
} }
@ -589,7 +602,9 @@ void SkeletonEditGraphicsView::saveToXmlStream(QXmlStreamWriter *writer)
QList<QGraphicsItem *>::iterator it; QList<QGraphicsItem *>::iterator it;
QList<QGraphicsItem *> list = scene()->items(); QList<QGraphicsItem *> list = scene()->items();
std::map<SkeletonEditNodeItem *, int> nodeIdMap; std::map<SkeletonEditNodeItem *, int> nodeIdMap;
std::map<QGraphicsItemGroup *, int> groupIdMap;
int nextNodeId = 1; int nextNodeId = 1;
int nextGroupId = 1;
for (it = list.begin(); it != list.end(); ++it) { for (it = list.begin(); it != list.end(); ++it) {
if ((*it)->data(0).toString() == "node") { if ((*it)->data(0).toString() == "node") {
SkeletonEditNodeItem *nodeItem = static_cast<SkeletonEditNodeItem *>(*it); SkeletonEditNodeItem *nodeItem = static_cast<SkeletonEditNodeItem *>(*it);
@ -602,7 +617,12 @@ void SkeletonEditGraphicsView::saveToXmlStream(QXmlStreamWriter *writer)
if ((*it)->data(0).toString() == "node") { if ((*it)->data(0).toString() == "node") {
SkeletonEditNodeItem *nodeItem = static_cast<SkeletonEditNodeItem *>(*it); SkeletonEditNodeItem *nodeItem = static_cast<SkeletonEditNodeItem *>(*it);
writer->writeStartElement("node"); writer->writeStartElement("node");
std::map<QGraphicsItemGroup *, int>::iterator findGroup = groupIdMap.find(nodeItem->group());
if (findGroup == groupIdMap.end()) {
groupIdMap[nodeItem->group()] = nextGroupId++;
}
writer->writeAttribute("id", QString("node%1").arg(nodeIdMap[nodeItem])); writer->writeAttribute("id", QString("node%1").arg(nodeIdMap[nodeItem]));
writer->writeAttribute("group", QString("group%1").arg(groupIdMap[nodeItem->group()]));
writer->writeAttribute("type", nodeItem->isMaster() ? "master" : "slave"); writer->writeAttribute("type", nodeItem->isMaster() ? "master" : "slave");
writer->writeAttribute("pair", QString("node%1").arg(nodeIdMap[nodeItem->pair()])); writer->writeAttribute("pair", QString("node%1").arg(nodeIdMap[nodeItem->pair()]));
writer->writeAttribute("radius", QString("%1").arg(nodeItem->radius())); writer->writeAttribute("radius", QString("%1").arg(nodeItem->radius()));

View File

@ -353,6 +353,12 @@ void SkeletonToMesh::process()
group->meshId = meshlite_bmesh_generate_mesh(context, group->bmeshId, group->nodes[group->rootNode].bmeshNodeId); group->meshId = meshlite_bmesh_generate_mesh(context, group->bmeshId, group->nodes[group->rootNode].bmeshNodeId);
} }
int mergedMeshId = m_groups[0].meshId;
for (size_t i = 1; i < m_groups.size(); i++) {
mergedMeshId = meshlite_merge(context, mergedMeshId, m_groups[i].meshId);
}
/*
ExternalMesh *unionPolyhedron = makeExternalMeshFromMeshlite(context, m_groups[0].meshId); ExternalMesh *unionPolyhedron = makeExternalMeshFromMeshlite(context, m_groups[0].meshId);
for (size_t i = 1; i < m_groups.size(); i++) { for (size_t i = 1; i < m_groups.size(); i++) {
ExternalMesh *polyhedron = makeExternalMeshFromMeshlite(context, m_groups[i].meshId); ExternalMesh *polyhedron = makeExternalMeshFromMeshlite(context, m_groups[i].meshId);
@ -364,11 +370,13 @@ void SkeletonToMesh::process()
break; break;
} }
} }
*/
for (size_t i = 1; i < m_groups.size(); i++) { for (size_t i = 1; i < m_groups.size(); i++) {
meshlite_bmesh_destroy(context, m_groups[i].bmeshId); meshlite_bmesh_destroy(context, m_groups[i].bmeshId);
} }
/*
if (unionPolyhedron) { if (unionPolyhedron) {
int meshIdGeneratedFromExternal = makeMeshliteMeshFromExternal(context, unionPolyhedron); int meshIdGeneratedFromExternal = makeMeshliteMeshFromExternal(context, unionPolyhedron);
delete unionPolyhedron; delete unionPolyhedron;
@ -376,6 +384,10 @@ void SkeletonToMesh::process()
meshlite_export(context, meshIdGeneratedFromExternal, "/Users/jeremy/testlib.obj"); meshlite_export(context, meshIdGeneratedFromExternal, "/Users/jeremy/testlib.obj");
m_mesh = new Mesh(context, meshIdGeneratedFromExternal); m_mesh = new Mesh(context, meshIdGeneratedFromExternal);
} }
*/
m_mesh = new Mesh(context, mergedMeshId);
meshlite_destroy_context(context); meshlite_destroy_context(context);
emit finished(); emit finished();
} }