/** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. * @param d1 first detail. * @param d2 second detail. * @param d1id id first detail. * @param d2id id second detail. * @param indexD1 index edge in first detail. * @param indexD2 index edge in second detail. * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. */ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { VToolUnionDetails *unionDetails = 0; quint32 id = _id; if (typeCreation == Source::FromGui) { id = data->getNextId(); } else { if (parse != Document::FullParse) { doc->UpdateToolData(id, data); } } VAbstractTool::AddRecord(id, Tool::UnionDetails, doc); if (parse == Document::FullParse) { //Scene doesn't show this tool, so doc will destroy this object. unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc); QHash<quint32, VDataTool*>* tools = doc->getTools(); tools->insert(id, unionDetails); for (int i = 0; i < d1.CountNode(); ++i) { doc->IncrementReferens(d1.at(i).getId()); } for (int i = 0; i < d2.CountNode(); ++i) { doc->IncrementReferens(d2.at(i).getId()); } } VNodeDetail det1p1; VNodeDetail det1p2; d1.NodeOnEdge(indexD1, det1p1, det1p2); Q_UNUSED(det1p2); VPointF point1; VPointF point2; PointsOnEdge(d1, indexD1, point1, point2, data); VPointF point3; VPointF point4; PointsOnEdge(d2, indexD2, point3, point4, data); const qreal dx = point1.x() - point4.x(); const qreal dy = point1.y() - point4.y(); point3.setX(point3.x()+dx); point3.setY(point3.y()+dy); point4.setX(point4.x()+dx); point4.setY(point4.y()+dy); const qreal angle = QLineF(point4.toQPointF(), point3.toQPointF()).angleTo(QLineF(point1.toQPointF(), point2.toQPointF())); qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. if (typeCreation == Source::FromGui) { qint32 j = 0, i = 0; VDetail newDetail; do { AddToNewDetail(unionDetails, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id); ++i; if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2) { do { FindJ(pointsD2, d2, indexD2, j); if (pointsD2 == d2.RemoveEdge(indexD2).CountNode() -2) { break; } if (j >= d2.RemoveEdge(indexD2).CountNode()) { j=0; } AddToNewDetail(unionDetails, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, dx, dy, det1p1.getId(), angle); ++pointsD2; ++j; } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode()); } } while (i < d1.RemoveEdge(indexD1).CountNode()); newDetail.setName("Detail"); newDetail.setWidth(d1.getWidth()); VToolDetail::Create(0, newDetail, scene, doc, data, parse, Source::FromTool); QHash<quint32, VDataTool*>* tools = doc->getTools(); SCASSERT(tools != nullptr); { VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id)); SCASSERT(toolDet != nullptr); bool ask = false; toolDet->Remove(ask); } VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d2id)); SCASSERT(toolDet != nullptr); bool ask = false; toolDet->Remove(ask); } else { quint32 idCount = 0; qint32 j = 0, i = 0; do { UpdatePoints(id, data, d1.RemoveEdge(indexD1), i, idCount); ++i; if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2) { do { FindJ(pointsD2, d2, indexD2, j); if (pointsD2 == d2.RemoveEdge(indexD2).CountNode()-2) { break; } if (j >= d2.RemoveEdge(indexD2).CountNode()) { j=0; } UpdatePoints(id, data, d2.RemoveEdge(indexD2), j, idCount, dx, dy, det1p1.getId(), angle); ++pointsD2; ++j; } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode()); } } while (i<d1.RemoveEdge(indexD1).CountNode()); } return nullptr; }
// need to modify this function!!! void runMDCD(sym_t* newfile) { int i,k, length; char conmsg[500]; char convt[32]; int lastcopy = 1; cmd_t* tmpcmd; // N=newsize for (i = 1; i < N + 1; i++) { // printf("MDCD %dth round \n", i); if (!lastcopy) { // must an insert Local_Optimum[i] = Local_Optimum[i - 1] + sizeof(sym_t); } else { // i.e. lastcopy = 1 Local_Optimum[i] = Local_Optimum[i-1] + sizeof(sym_t) + INSERT_COST; } // defaults to a download command lastcopy = 0; S[i] = i - 1; sprintf(conmsg,"[%d] %s ", Local_Optimum[i], "Download: "); sprintf(convt," %04X %04X ", newfile[i-1].offset, newfile[i-1].address ); strcat(conmsg, convt); tmpcmd = (cmd_t*)malloc(sizeof(cmd_t)); tmpcmd->type = 0; tmpcmd->inew = i-1; tmpcmd->iold = -1; tmpcmd->length = sizeof(sym_t); // printf("%s \n", conmsg); Segment Seg; Seg = FindJ(i); // printf("Seg Starting Y %d", Seg.Starting_Y); for ( k = (Seg.Starting_Y); k <= i - 1; k++ ) { int l = 0; if (Seg.source == 1 || Seg.source == 3) { l = (k - Seg.Starting_Y + Seg.Starting_X); } else if (Seg.source == 2 || Seg.source == 4) { l = (Seg.Starting_X - (k - Seg.Starting_Y) ); } // set beta char copycmd = ' '; //if (Table_C[l][k].offset == 0 && Table_C[l][k].address == 0) { if (Seg.offset == 0 && Seg.address == 0) { beta = COPY_COST; copycmd = ' '; } //else if (Table_C[l][k].offset != 0 && Table_C[l][k].address != 0) { else if (Seg.offset != 0 && Seg.address != 0) { beta = COPYXY_COST; copycmd = 'z'; } //else if (Table_C[l][k].offset != 0 && Table_C[l][k].address == 0) { else if (Seg.offset != 0 && Seg.address == 0) { beta = COPYX_COST; copycmd = 'x'; } else { beta = COPYY_COST; // COPYY_COST is the same copycmd = 'y'; } if (Local_Optimum[i] >= Local_Optimum[k] + beta) { lastcopy = 1; Local_Optimum[i] = Local_Optimum[k] + beta; S[i] = k; int l = 0; if (Seg.source == 1 || Seg.source == 3) { l = (k - Seg.Starting_Y + Seg.Starting_X); } else if (Seg.source == 2 || Seg.source == 4) { l = (Seg.Starting_X - (k - Seg.Starting_Y) ); } length = i - k; if (Seg.source == 1) { sprintf(conmsg," [%d] [%4d|%4d] %s%c %s ", Local_Optimum[i], Seg.offset, Seg.address, "Copy", copycmd, "from old code forward, StartingX = "); sprintf(convt," %d ", l ); strcat(conmsg, convt); strcat(conmsg, ", Starting Y =" ); sprintf(convt," %d ", k ); strcat(conmsg, convt); strcat(conmsg, ", length = " ); sprintf(convt," %d ", length ); strcat(conmsg, convt); tmpcmd->length = length; tmpcmd->inew = k; tmpcmd->iold = l; if(copycmd == ' ') { tmpcmd->type = 1; } else if(copycmd == 'x') { tmpcmd->type =2; tmpcmd->x_off = Seg.offset; tmpcmd->y_off = 0; } else if(copycmd == 'y') { tmpcmd->type = 3; tmpcmd->x_off = 0; tmpcmd->y_off = Seg.address; } else if(copycmd == 'z') { tmpcmd->type =4; tmpcmd->x_off = Seg.offset; tmpcmd->y_off = Seg.address; } } } } strcpy(Message[i], conmsg); cmd[i] = *tmpcmd; } }
void runMDCD(unsigned char * newfile) { int i,k, length; char conmsg[500]; char convt[32]; for (i = 1; i < N + 1; i++) { // printf("MDCD %dth round \n", i); Local_Optimum[i] = Local_Optimum[i - 1] + 1; S[i] = i - 1; sprintf(conmsg," %s ", " Download: "); sprintf(convt," %d ", newfile[i-1] ); strcat(conmsg, convt); // printf("%s \n", conmsg); Segment Seg; Seg = FindJ(i); // printf("Seg Starting Y %d", Seg.Starting_Y); for ( k = (Seg.Starting_Y); k <= i - 1; k++ ) { if (Local_Optimum[i] >= Local_Optimum[k] + beta) { Local_Optimum[i] = Local_Optimum[k] + beta; S[i] = k; int l = 0; if (Seg.source == 1 || Seg.source == 3) { l = (k - Seg.Starting_Y + Seg.Starting_X); } else if (Seg.source == 2 || Seg.source == 4) { l = (Seg.Starting_X - (k - Seg.Starting_Y) ); } length = i - k; if (Seg.source == 1) { sprintf(conmsg," %s ", " Copy from old code forward, StartingX = "); sprintf(convt," %d ", l ); strcat(conmsg, convt); strcat(conmsg, ", Starting Y =" ); sprintf(convt," %d ", k ); strcat(conmsg, convt); strcat(conmsg, ", length = " ); sprintf(convt," %d ", length ); strcat(conmsg, convt); } else if(Seg.source == 2){ sprintf(conmsg," %s ", " Copy from old code backward, StartingX = "); sprintf(convt," %d ", l ); strcat(conmsg, convt); strcat(conmsg, ", Starting Y =" ); sprintf(convt," %d ", k ); strcat(conmsg, convt); strcat(conmsg, ", length = " ); sprintf(convt," %d ", length ); strcat(conmsg, convt); }else if(Seg.source == 3){ sprintf(conmsg," %s ", " Copy from new code forward, StartingX = "); sprintf(convt," %d ", l ); strcat(conmsg, convt); strcat(conmsg, ", Starting Y =" ); sprintf(convt," %d ", k ); strcat(conmsg, convt); strcat(conmsg, ", length = " ); sprintf(convt," %d ", length ); strcat(conmsg, convt); }else if (Seg.source == 4) { sprintf(conmsg," %s ", " Copy from new code forward, StartingX = "); sprintf(convt," %d ", l ); strcat(conmsg, convt); strcat(conmsg, ", Starting Y =" ); sprintf(convt," %d ", k ); strcat(conmsg, convt); strcat(conmsg, ", length = " ); sprintf(convt," %d ", length ); strcat(conmsg, convt); } } } // char * tmpstr = (char *)malloc(300 * sizeof(char)); // strcpy(tmpstr,conmsg); strcpy(Message[i], conmsg); // Message[i] = tmpstr ; // printf("%s \n", Message[i]); } }