char * BitmapHandler::findBmpFile(const std::string &name, int &w, int &h, int mode, bool useCache) { std::unique_lock<std::recursive_mutex> m(_mutex); auto it = _bitmaps.find(name); bool exists = it != _bitmaps.end(); if(exists && useCache) { std::shared_ptr<Bitmap> b = (*it).second; w = b->w; h = b->h; return makeCopy(b->bmp, w, h, mode); } else { m.unlock(); char *data = loadBmpFile(name, w, h, mode); if(data!=NULL) { addBmp(name, data, w, h, mode); char *bmp = makeCopy(data, w, h, mode); free(data); return bmp; } } return NULL; }
void CreateHexCore::deleteOutside(vtkUnstructuredGrid *grid) { MeshPartition part(grid, true); QVector<bool> is_inside(grid->GetNumberOfCells(), false); vtkIdType id_start = -1; double dmin = 1e99; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (isVolume(id_cell, grid)) { vec3_t x = cellCentre(grid, id_cell); double d = (x - m_Xi).abs(); if (d < dmin) { dmin = d; id_start = id_cell; } } } if (id_start == -1) { EG_BUG; } is_inside[id_start] = true; bool added = true; while (added) { added = false; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (is_inside[id_cell]) { for (int j = 0; j < part.c2cGSize(id_cell); ++j) { vtkIdType id_neigh = part.c2cGG(id_cell, j); if (id_neigh >= 0) { if (!is_inside[id_neigh]) { is_inside[id_neigh] = true; added = true; } } } } } } int N = 0; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, grid)) { is_inside[id_cell] = true; } if (is_inside[id_cell]) { ++N; } } QVector<vtkIdType> cls(N); N = 0; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (is_inside[id_cell]) { cls[N] = id_cell; ++N; } } EG_VTKSP(vtkUnstructuredGrid, return_grid); makeCopy(grid, return_grid, cls); makeCopy(return_grid, grid); }
CgalTriCadInterface::CgalTriCadInterface(vtkUnstructuredGrid *grid) { m_BGrid = vtkUnstructuredGrid::New(); makeCopy(grid, m_BGrid); m_BPart.setGrid(m_BGrid, true); double feature_angle; EG_STOPDATE("2015-01-01"); //getXmlSetting("engrid/surface/settings", "feature_angle", feature_angle); getSet("surface meshing", "feature angle", 20, feature_angle); feature_angle = GeometryTools::deg2rad(feature_angle); // build triangle tree { m_Triangles.clear(); QVector<vtkIdType> tris; getAllCellsOfType(VTK_TRIANGLE, tris, m_BGrid); m_Triangles.fill(Triangle(), tris.size()); m_Tri2Grid.fill(-1, tris.size()); int i = 0; foreach (vtkIdType id_cell, tris) { EG_GET_CELL(id_cell, m_BGrid); vec3_t a, b, c; m_BGrid->GetPoint(pts[0], a.data()); m_BGrid->GetPoint(pts[1], b.data()); m_BGrid->GetPoint(pts[2], c.data()); m_Triangles[i] = Triangle(Point(a[0], a[1], a[2]), Point(b[0], b[1], b[2]), Point(c[0], c[1], c[2])); m_Tri2Grid[i] = id_cell; ++i; } m_TriangleTree.rebuild(m_Triangles.begin(), m_Triangles.end()); m_TriangleTree.accelerate_distance_queries(); }
void SeligAirfoilReader::operate() { try { readInputFileName(""); if (isValid()) { QFile file(getFileName()); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream f(&file); f.readLine(); EG_VTKSP(vtkPolyData, poly); double read_value; int num_upper, num_lower; f >> read_value; num_upper = int(read_value); f >> read_value; num_lower = int(read_value); int num_nodes = num_lower + num_upper - 1; QVector<vec3_t> coord(num_nodes, vec3_t(0,0,0)); for (int i = 0; i < num_upper; ++i) { f >> coord[i][0] >> coord[i][1]; } double dummy; f >> dummy; f >> dummy; for (int i = num_nodes - 1; i >= num_upper; --i) { f >> coord[i][0] >> coord[i][1]; } EG_VTKSP(vtkPoints, points); points->SetNumberOfPoints(num_nodes); poly->SetPoints(points); poly->Allocate(num_nodes); for (vtkIdType id_node = 0; id_node < num_nodes; ++id_node) { poly->GetPoints()->SetPoint(id_node, coord[id_node].data()); } for (vtkIdType id_node = 0; id_node < num_nodes; ++id_node) { vtkIdType pts[2]; pts[0] = id_node; if (id_node < num_nodes-1) { pts[1] = id_node + 1; } else { pts[1] = 0; } poly->InsertNextCell(VTK_LINE, 2, pts); } EG_VTKSP(vtkDelaunay2D, tri); tri->SetInputData(poly); tri->SetSourceData(poly); EG_VTKSP(vtkEgPolyDataToUnstructuredGridFilter, poly2ug); poly2ug->SetInputConnection(tri->GetOutputPort()); poly2ug->Update(); makeCopy(poly2ug->GetOutput(), m_Grid); UpdateNodeIndex(m_Grid); UpdateCellIndex(m_Grid); } } catch (Error err) { err.display(); } }
void BrlcadReader::createBackgroundGeometry() { // make a backup of the existing grid EG_VTKSP(vtkUnstructuredGrid, backup_grid); makeCopy(m_Grid, backup_grid); QSet<int> bcs = GuiMainWindow::pointer()->getAllBoundaryCodes(); // count total number of nodes and faces for background geometry int num_nodes = 0; int num_faces = 0; foreach (int bc, bcs) { int i_grid = m_BC2GridIndex[bc]; num_nodes += m_Grids[i_grid]->GetNumberOfPoints(); num_faces += m_Grids[i_grid]->GetNumberOfCells(); }
// overloading = // The operator = does not work well with pointers bool slist::operator==(const slist& linkedList) { Node * pointertoLeftHandSideLinkedList = this->Front; slist makeCopy(linkedList); Node * pointertoRightHandSideLinkedList = makeCopy.Front; // case 1, check for size if(this->Count != linkedList.Count) return false; bool isStillSame = true; // case 2, if size is same while (true) { if(pointertoLeftHandSideLinkedList == NULL) break; if(pointertoLeftHandSideLinkedList->Elem != pointertoRightHandSideLinkedList->Elem) isStillSame = false; pointertoLeftHandSideLinkedList = pointertoLeftHandSideLinkedList->Next; pointertoRightHandSideLinkedList = pointertoRightHandSideLinkedList->Next; } return isStillSame; }
void BrlcadReader::processStlFile(QString file_name, bool append_to_list) { vtkSTLReader *stl = vtkSTLReader::New(); stl->MergingOn(); stl->SetFileName(file_name.toAscii().data()); stl->Update(); EG_VTKSP(vtkPolyData, poly); poly->DeepCopy(stl->GetOutput()); poly->BuildCells(); double L = 1e99; for (vtkIdType cellId = 0; cellId < poly->GetNumberOfCells(); ++cellId) { vtkIdType *pts, Npts; poly->GetCellPoints(cellId, Npts, pts); for (int i = 0; i < Npts; ++i) { vec3_t x1, x2; poly->GetPoints()->GetPoint(pts[i], x1.data()); if (i == Npts - 1) { poly->GetPoints()->GetPoint(pts[0], x2.data()); } else { poly->GetPoints()->GetPoint(pts[i+1], x2.data()); } L = min(L, (x1-x2).abs()); } } EG_VTKSP(vtkEgPolyDataToUnstructuredGridFilter, poly2ugrid); poly2ugrid->SetInput(poly); poly2ugrid->Update(); EG_VTKSP(vtkUnstructuredGrid, grid); allocateGrid(grid, poly2ugrid->GetOutput()->GetNumberOfCells(), poly2ugrid->GetOutput()->GetNumberOfPoints()); for (vtkIdType id_node = 0; id_node < poly2ugrid->GetOutput()->GetNumberOfPoints(); ++id_node) { vec3_t x; poly2ugrid->GetOutput()->GetPoints()->GetPoint(id_node, x.data()); grid->GetPoints()->SetPoint(id_node, x.data()); } for (vtkIdType id_cell = 0; id_cell < poly2ugrid->GetOutput()->GetNumberOfCells(); ++id_cell) { vtkIdType N_pts, *pts; vtkIdType type_cell = poly2ugrid->GetOutput()->GetCellType(id_cell); poly2ugrid->GetOutput()->GetCellPoints(id_cell, N_pts, pts); grid->InsertNextCell(type_cell, N_pts, pts); } EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code"); EG_VTKDCC(vtkIntArray, orgdir, grid, "cell_orgdir"); EG_VTKDCC(vtkIntArray, voldir, grid, "cell_voldir"); EG_VTKDCC(vtkIntArray, curdir, grid, "cell_curdir"); for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { cell_code->SetValue(id_cell, 9999); orgdir->SetValue(id_cell, 0); voldir->SetValue(id_cell, 0); curdir->SetValue(id_cell, 0); } if (append_to_list) { SetBoundaryCode set_bc; set_bc.setGrid(grid); set_bc.setAllSurfaceCells(); int bc_max = 1; bool done = false; do { vtkIdType id_start = -1; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (cell_code->GetValue(id_cell) == 9999) { id_start = id_cell; break; } } if (id_start == -1) { done = true; } else { set_bc.setFeatureAngle(20.0); set_bc.setBC(bc_max); set_bc.setProcessAll(true); set_bc.setSelectAllVisible(false); set_bc.setOnlyPickedCell(false); set_bc.setOnlyPickedCellAndNeighbours(false); set_bc.setStart(id_start); set_bc(); ++bc_max; } } while (!done); cout << "file: " << qPrintable(file_name) << endl; for (int bc = 1; bc < bc_max; ++bc) { QList<vtkIdType> cells; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (cell_code->GetValue(id_cell) == bc) { cells.append(id_cell); } } vtkUnstructuredGrid *new_grid = vtkUnstructuredGrid::New(); QString bc_txt; bc_txt.setNum(bc); if (bc_max >= 10) { bc_txt = bc_txt.rightJustified(2, '0'); } QFileInfo file_info(file_name); m_BCNames[new_grid] = file_info.baseName() + "." + bc_txt; cout << " " << qPrintable(file_info.baseName() + "." + bc_txt) << endl; makeCopy(grid, new_grid, cells); m_Grids.append(new_grid); } } else { makeCopy(grid, m_Grid); } }
bool Way::canFind(const Board& board, const sf::Vector2f& pixelsStartPosition) { makeCopy(board); mValueParameter=-1; sf::Vector2i chosenFieldPosition(FieldManager::getInstance().getChosenFieldPosition()); mWorkingBoard[chosenFieldPosition.x][chosenFieldPosition.y]=9; sf::Vector2u actualPosition(static_cast<unsigned>(pixelsStartPosition.x / gi::FIELD_WIDTH), static_cast<unsigned>(pixelsStartPosition.y / gi::FIELD_HEIGHT)); mWorkingBoard[actualPosition.x][actualPosition.y]=mValueParameter; --mValueParameter; std::queue<sf::Vector2u> pointsList; pointsList.push(actualPosition); unsigned int pointsListSize=0; while(pointsList.size() != 0) { pointsListSize=pointsList.size(); for(unsigned int i=0; i < pointsListSize; ++i) { actualPosition=pointsList.front(); pointsList.pop(); if(mWorkingBoard[actualPosition.x + 1][actualPosition.y] == 2) // found exit on right field { return true; } else if(mWorkingBoard[actualPosition.x + 1][actualPosition.y] == 0) // right field { mWorkingBoard[actualPosition.x + 1][actualPosition.y]=mValueParameter; pointsList.push(sf::Vector2u(actualPosition.x + 1, actualPosition.y)); } if(mWorkingBoard[actualPosition.x][actualPosition.y + 1] == 0) // down field { mWorkingBoard[actualPosition.x][actualPosition.y + 1]=mValueParameter; pointsList.push(sf::Vector2u(actualPosition.x, actualPosition.y + 1)); } if(mWorkingBoard[actualPosition.x][actualPosition.y - 1] == 0) // up field { mWorkingBoard[actualPosition.x][actualPosition.y - 1]=mValueParameter; pointsList.push(sf::Vector2u(actualPosition.x, actualPosition.y - 1)); } if(actualPosition.x > 1) { if(mWorkingBoard[actualPosition.x - 1][actualPosition.y] == 0) // left field { mWorkingBoard[actualPosition.x - 1][actualPosition.y]=mValueParameter; pointsList.push(sf::Vector2u(actualPosition.x - 1, actualPosition.y)); } } } --mValueParameter; } return false; }
void MultiSolidAsciiStlReader::operate() { QFileInfo file_info(GuiMainWindow::pointer()->getFilename()); readInputFileName(file_info.completeBaseName() + ".stl"); if (isValid()) { double tol = QInputDialog::getText(NULL, "enter STL tolerance", "tolerance", QLineEdit::Normal, "1e-10").toDouble(); QList<QString> buffer; QList<QString> bc_name; { QFile file(getFileName()); if (!file.open(QFile::ReadOnly)) { EG_ERR_RETURN("unable to open file"); } QTextStream f(&file); QString buf = ""; QString name = "unknown"; while (!f.atEnd()) { QString line = f.readLine(); buf += line + "\n"; // endline?? if (line.left(8) == "endsolid") { buffer.append(buf); buf = ""; bc_name.append(name); } else if (line.left(5) == "solid") { name = line.right(line.size() - 6); } } } bool first = true; int last_bc = 1; foreach (QString buf, buffer) { QString file_name = getFileName() + ".tmp"; { QFile file(file_name); if (!file.open(QFile::WriteOnly)) { EG_ERR_RETURN("unable to open file\"" + file_name + "\" for writing"); } QTextStream f(&file); f << buf << endl; } StlReader stl; stl.setTolerance(tol); stl.setFileName(file_name); EG_VTKSP(vtkUnstructuredGrid, grid); stl.setGrid(grid); stl.setMaximalCleaningIterations(3); stl(); // @todo set boundary names EG_VTKDCC(vtkIntArray, bc, grid, "cell_code"); for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { bc->SetValue(id_cell, last_bc); } ++last_bc; if (first) { first = false; makeCopy(grid, m_Grid); } else { MeshPartition part1(m_Grid, true); MeshPartition part2(grid, true); part1.addPartition(part2); } } last_bc = 1; GuiMainWindow::pointer()->resetXmlDoc(); GuiMainWindow::pointer()->clearBCs(); foreach (QString name, bc_name) { GuiMainWindow::pointer()->addBC(last_bc, BoundaryCondition(name, "patch")); ++last_bc; }
void BlenderReader::operate() { try { QFileInfo file_info(GuiMainWindow::pointer()->getFilename()); readInputFileName(file_info.completeBaseName() + ".begc", false); if (isValid()) { // read raw data from exported file QFile file(getFileName()); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream f(&file); QList<vec3_t> rnodes; QList<QVector<int> > rfaces; int num_parts; f >> num_parts; QVector<QString> part_name(num_parts); for (int i_part = 0; i_part < num_parts; ++i_part) { f >> part_name[i_part]; } QVector<QString> sorted_part_name = part_name; qSort(sorted_part_name); QVector<int> part_bc(part_name.size()); for (int i_part = 0; i_part < num_parts; ++i_part) { part_bc[i_part] = sorted_part_name.indexOf(part_name[i_part]) + 1; } for (int i_part = 0; i_part < num_parts; ++i_part) { int num_nodes, num_faces; f >> num_nodes >> num_faces; for (int i = 0; i < num_nodes; ++i) { vec3_t x; f >> x[0] >> x[1] >> x[2]; rnodes.push_back(x); } for (int i = 0; i < num_faces; ++i) { int N; f >> N; QVector<int> face(N+1); face[0] = i_part; for (int j = 0; j < N; ++j) { f >> face[j+1]; } rfaces.push_back(face); } } QVector<vec3_t> nodes(rnodes.size()); qCopy(rnodes.begin(), rnodes.end(), nodes.begin()); QVector<QVector<int> > faces(rfaces.size()); qCopy(rfaces.begin(), rfaces.end(), faces.begin()); // find smallest edge length double L = 1e99; foreach (QVector<int> face, faces) { for (int i = 1; i < face.size(); ++i) { int n1 = face[i]; int n2 = face[1]; if (i < face.size() - 1) { n2 = face[i+1]; } double l = (nodes[n1] - nodes[n2]).abs(); L = min(l, L); } } cout << "smallest edge length is " << L << endl; // delete duplicate nodes PointFinder finder; finder.setPoints(nodes); QList<vec3_t> non_dup; QVector<int> o2n(nodes.size()); int num_non_dup = 0; for (int i = 0; i < nodes.size(); ++i) { o2n[i] = num_non_dup; bool dup = false; QVector<int> close_points; finder.getClosePoints(nodes[i], close_points); foreach (int j, close_points) { if (i > j) { double l = (nodes[i] - nodes[j]).abs(); if (l < m_RelativeTolerance*L || l == 0) { o2n[i] = o2n[j]; dup = true; break; } } } if (!dup) { non_dup.push_back(nodes[i]); ++num_non_dup; } } EG_VTKSP(vtkUnstructuredGrid, new_grid); allocateGrid(new_grid, faces.size(), non_dup.size()); EG_VTKDCC(vtkIntArray, cell_code, new_grid, "cell_code"); EG_VTKDCC(vtkIntArray, orgdir, new_grid, "cell_orgdir"); EG_VTKDCC(vtkIntArray, voldir, new_grid, "cell_voldir"); EG_VTKDCC(vtkIntArray, curdir, new_grid, "cell_curdir"); vtkIdType id_node = 0; foreach (vec3_t x, non_dup) { new_grid->GetPoints()->SetPoint(id_node, x.data()); ++id_node; } foreach (QVector<int> face, faces) { if (face.size() == 4) { vtkIdType pts[3]; pts[0] = o2n[face[1]]; pts[1] = o2n[face[2]]; pts[2] = o2n[face[3]]; vtkIdType id_cell = new_grid->InsertNextCell(VTK_TRIANGLE, 3, pts); cell_code->SetValue(id_cell, part_bc[face[0]]); orgdir->SetValue(id_cell, 0); voldir->SetValue(id_cell, 0); curdir->SetValue(id_cell, 0); } if (face.size() == 5) { vtkIdType pts[4]; pts[0] = o2n[face[1]]; pts[1] = o2n[face[2]]; pts[2] = o2n[face[3]]; pts[3] = o2n[face[4]]; vtkIdType id_cell = new_grid->InsertNextCell(VTK_QUAD, 4, pts); cell_code->SetValue(id_cell, part_bc[face[0]]); orgdir->SetValue(id_cell, 0); voldir->SetValue(id_cell, 0); curdir->SetValue(id_cell, 0); } } if (m_Append) { EG_BUG; MeshPartition new_part(new_grid); new_part.setAllCells(); m_Part.addPartition(new_part); } else { makeCopy(new_grid, m_Grid); } UpdateNodeIndex(m_Grid); UpdateCellIndex(m_Grid); // check and set the boundary names if required int update_required = true; QSet<int> old_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes(); if (old_bcs.size() == part_name.size()) { QSet<QString> old_names; foreach (int bc, old_bcs) { old_names.insert(GuiMainWindow::pointer()->getBC(bc).getName()); } QSet<QString> new_names; foreach (QString name, part_name) { new_names.insert(name); }
/** * Funkce interpret projde a vykona zoznam trojadresnyho kodu. * @param iList Seznam triadresneho kodu. * @param btree Binarni strom reprezentujici tabulku symbolu. * @return Uspesnost funkce. */ int interpret(tListOfInstr * iList, BNode *btree) { // chod na MAIN navesti v seznamu instrukci listFirst(iList); listGotoMain(iList); tInstr *I = listGetData(iList); g_btree = btree; int PUSHING = 0; // tData pre return tData retData; retData.varType = T_NOTDEF; retData.hasValue = 0; g_retData = &retData; // tData pre push tData pushData; pushData.varType = T_NOTDEF; pushData.hasValue = 0; // Data pro 3 adresy instrukci tData *data1 = NULL; tData *data2 = NULL; tData *data3 = NULL; tData *var = NULL; //pomocni pri prohladavani tData dataC ; //pomocni pri vyrazech a = a .. b; .... // Pomocny zasobnik pro skoky jumpStack jStack; jStackInit(&jStack); g_jStack = &jStack; // Pomocny dvousmerny seznam pro funkce tListOfCall list2; hListInit(&list2); g_list = &list2; hListInsert(&list2,NULL,S_LAB); // Sme na main navesti ? if(I->instType != I_LAB_MAIN) { errorFree(); return EINT; } // Projdi a vykonej triadresny kod while (1) { // Ziskej instrukci ze seznamu I = listGetData(iList); // Prirad adresy do premennych data1 = I->addr1; data2 = I->addr2; data3 = I->addr3; // pokus se vyhledat polozky ze stromu v pomocnej strukture if(data1 != NULL && I->instType != I_JUMP && I->instType != I_JMPN) { var = hSearchToLab(&list2, data1, PUSHING); if(var != NULL) data1 = var; } if(data2 != NULL) { var = hSearchToLab(&list2, data2, PUSHING); if(var != NULL) data2 = var; } if(data3 != NULL && I->instType != I_JUMP) { var = hSearchToLab(&list2, data3, PUSHING); if(var != NULL) data3 = var; } // Podle typu instrukce vykonej operaci //////////////////////////////////// switch (I->instType) { // NAVESTI MAIN case I_LAB_MAIN: PUSHING = 1; break; // NAVESTI case I_LAB: break; // NAVESTI ZACATEK FUNKCE case I_LAB_S: PUSHING = 1; break; // NAVESTI KONEC PUSH case I_LAB_F: PUSHING = 0; hListInsert(&list2,NULL,S_LAB); break; // SOUCET case I_ADD: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = data2->value.dValue + data3->value.dValue; } } else { errorFree(); return EINT; } break; // MODULO case I_MOD: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { if(data3->value.dValue == 0) { errorFree(); return EINT; } data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = ((int)data2->value.dValue) % ((int)data3->value.dValue); } } else { errorFree(); return EINT; } break; // ODECITANI case I_SUB: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = data2->value.dValue - data3->value.dValue; } } else { errorFree(); return EINT; } break; // NASOBENI case I_MUL: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = data2->value.dValue * data3->value.dValue; } } else { errorFree(); return EINT; } break; // DELENI case I_DIV: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { if(data3->value.dValue == 0) { errorFree(); return EINT; } data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = data2->value.dValue / data3->value.dValue; } data1->value.dValue = data2->value.dValue / data3->value.dValue; } else { errorFree(); return EINT; } break; // KONKATENACE case I_CONCAT: if(data2->varType == T_STRING && data3->varType == T_STRING) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->varType = T_STRING; data1->hasValue = 1; strInit(&data1->value.sValue); strConCat(&data2->value.sValue, &data3->value.sValue, &data1->value.sValue); } } else { errorFree(); return EINT; } break; // KONKATENACE case I_SLENGTH: if(data3->varType == T_STRING) { int a = data3->value.sValue.length; if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->hasValue = HAVE_VALUE; data1->varType = T_NUMBER; data1->value.dValue = a; } else { errorFree(); return EINT; } break; // UMOCNENI case I_POWER: if(data2->varType == T_NUMBER && data3->varType == T_NUMBER) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->varType = T_NUMBER; data1->hasValue = 1; data1->value.dValue = 1; data1->value.dValue = pow( data2->value.dValue, data3->value.dValue); } } else { errorFree(); return EINT; } break; // POROVNANI case I_EQUAL: data1->varType = T_BOOLEAN; data1->hasValue = 1; if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { switch(data2->varType) { case T_NUMBER: if (data2->value.dValue == data3->value.dValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_STRING: if (strcmp(data2->value.sValue.str, data3->value.sValue.str) == 0) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_BOOLEAN: if (data2->value.bValue == data3->value.bValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_NIL: data1->value.bValue = 1; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { data1->value.bValue = 0; data1->varType = T_BOOLEAN; } break; // NEGACE POROVNANI case I_NEQUAL: data1->varType = T_BOOLEAN; data1->hasValue = 1; if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { switch(data2->varType) { case T_NUMBER: if (data2->value.dValue == data3->value.dValue) data1->value.bValue = 0; else data1->value.bValue = 1; break; case T_STRING: if (strcmp(data2->value.sValue.str, data3->value.sValue.str) == 0) data1->value.bValue = 0; else data1->value.bValue = 1; break; case T_BOOLEAN: if (data2->value.bValue == data3->value.bValue) data1->value.bValue = 0; else data1->value.bValue = 1; break; case T_NIL: data1->value.bValue = 0; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { data1->value.bValue = 0; data1->varType = T_BOOLEAN; } break; // MENSI NEZ case I_LCMP: if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { switch (data2->varType) { case T_NUMBER: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (data2->value.dValue < data3->value.dValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_STRING: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (strcmp(data2->value.sValue.str, data3->value.sValue.str) < 0) data1->value.bValue = 1; else data1->value.bValue = 0; break; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { errorFree(); return EINT; } break; // VETSI NEZ case I_GCMP: if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { data1->hasValue = HAVE_VALUE; switch (data2->varType) { case T_NUMBER: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (data2->value.dValue > data3->value.dValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_STRING: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (strcmp(data2->value.sValue.str, data3->value.sValue.str) > 0) data1->value.bValue = 1; else data1->value.bValue = 0; break; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { errorFree(); return EINT; } break; // MENSI ROVNO case I_ELCMP: if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { switch(data2->varType) { case T_NUMBER: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (data2->value.dValue <= data3->value.dValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_STRING: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (strcmp(data2->value.sValue.str, data3->value.sValue.str) <= 0) data1->value.bValue = 1; else data1->value.bValue = 0; break; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { errorFree(); return EINT; } break; // VETSI ROVNO case I_EGCMP: if(data2->varType == data3->varType) { if(data2->hasValue != 0 && data3->hasValue != 0) { switch (data2->varType) { case T_NUMBER: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (data2->value.dValue >= data3->value.dValue) data1->value.bValue = 1; else data1->value.bValue = 0; break; case T_STRING: data1->varType = T_BOOLEAN; data1->hasValue = 1; if (strcmp(data2->value.sValue.str, data3->value.sValue.str) >= 0) data1->value.bValue = 1; else data1->value.bValue = 0; break; default: errorFree(); return EINT; } } else { errorFree(); return EINT; } } else { errorFree(); return EINT; } break; // JE VYRAZ TRUE ? case I_STRUE: if(data1->varType == T_STRING) { strFree(&data1->value.sValue); data1->value.bValue = 1; } else if(data1->varType == T_BOOLEAN) { if(data1->value.bValue == 1) data1->value.bValue = 1; else data1->value.bValue = 0; } else if(data1->varType == T_NIL || data1->varType == T_NOTDEF) data1->value.bValue = 0; else data1->value.bValue = 1; data1->varType = T_BOOLEAN; break; // SKOK POKIAL FALSE case I_JMPN: if(data3->varType == T_BOOLEAN) { if(data3->value.bValue == 0) listGoto(iList, I->addr1); } break; // SKOK case I_JUMP: if(I->addr3 != NULL) jStackPush(&jStack,I); listGoto(iList, I->addr1); break; // PRIRAZENI case I_ASGN: if(data3->hasValue != 0) { dataC.varType = data3->varType; data1->hasValue = 1; makeCopy(data3, &dataC); if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->varType = data3->varType; switch (dataC.varType) { case T_NUMBER: data1->value.dValue = dataC.value.dValue; break; case T_STRING: strInitText(&data1->value.sValue, dataC.value.sValue.str); break; case T_BOOLEAN: data1->value.bValue = dataC.value.bValue; break; case T_NIL: data1->value.bValue = dataC.value.bValue; break; default: if(dataC.varType == T_STRING) strFree(&dataC.value.sValue); errorFree(); return EINT; } } else { if(dataC.varType == T_STRING) strFree(&dataC.value.sValue); errorFree(); return EINT; } if(dataC.varType == T_STRING) strFree(&dataC.value.sValue); break; // ZAPAMATOVANA POLOZKA Z POSLEDNIHO VOLANI case I_ASGNR: if(retData.hasValue != 0) { if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->hasValue = 1; data1->varType = retData.varType; switch (retData.varType) { case T_NUMBER: data1->value.dValue = retData.value.dValue; break; case T_STRING: strInitText(&data1->value.sValue, retData.value.sValue.str); break; case T_BOOLEAN: data1->value.bValue = retData.value.bValue; break; case T_NIL: data1->value.bValue = retData.value.bValue; break; default: errorFree(); return EINT; } if(retData.varType == T_STRING) strFree(&retData.value.sValue); retData.varType = T_NOTDEF; } else { strFree(&retData.varKey); if(retData.varType == T_STRING) strFree(&retData.value.sValue); retData.varType = T_NOTDEF; errorFree(); return EINT; } break; // READ FUNKCE // podla fora sa ma pri cisle chovat inak case I_READ: if(data1->varType == T_STRING) strFree(&data1->value.sValue); if(data3->varType == T_NUMBER) { if(data3->value.dValue < 0) { errorFree(); return ESEM; } strInit(&data1->value.sValue); readStrToNUMB(&data1->value.sValue,data3->value.dValue); data1->varType = T_STRING; } else if(data3->varType == T_STRING) { if(data3->value.sValue.length >= 2) { if((data3->value.sValue.str[0] == '*') && (data3->value.sValue.str[1] == 'n')) { if(scanf("%lf",&data1->value.dValue) != 1) { data1->varType = T_NIL; data1->value.bValue = 0; } else data1->varType = T_NUMBER; } else if((data3->value.sValue.str[0] == '*') && (data3->value.sValue.str[1] == 'l')) { strInit(&data1->value.sValue); readStrToNl(&data1->value.sValue); data1->varType = T_STRING; } else if((data3->value.sValue.str[0] == '*') && (data3->value.sValue.str[1] == 'a')) { strInit(&data1->value.sValue); readStrToEOF(&data1->value.sValue); data1->varType = T_STRING; } else { errorFree(); return ESEM; } } else { errorFree(); return ESEM; } } else { errorFree(); return ESYN; } data1->hasValue = HAVE_VALUE; break; // WRITE FUNKCE case I_WRITE: if (data1->hasValue != 0) { if(data1->varType == T_NUMBER) printf("%g", data1->value.dValue); else if (data1->varType == T_STRING) { // KONECNY AUTOMAT PRO VYPIS int writeState = 0; for(int i = 0; i < data1->value.sValue.length; i++) { switch(writeState) { case 0: if(data1->value.sValue.str[i] == LOMITKO) writeState = 1; else putchar(data1->value.sValue.str[i]); break; case 1: if(data1->value.sValue.str[i] == 'n') printf("\n"); else if(data1->value.sValue.str[i] == 't') printf("\t"); else if(data1->value.sValue.str[i] == LOMITKO) printf("\\"); else if (data1->value.sValue.str[i] == UVOZOVKY) printf("\""); else if(data1->value.sValue.str[i] == NOVYRADEK) break; else putchar(data1->value.sValue.str[i]); writeState = 0; break; } } } else { errorFree(); return EINT; } } else { errorFree(); return EINT; } break; // FUNKCE FTYPE VRACI TYP case I_FTYPE: if (data1->varType == T_STRING) strFree(&data1->value.sValue); data1->hasValue = 1; switch(data3->varType) { case T_NOTDEF: strInitText(&data1->value.sValue, "nil"); break; case T_NUMBER: strInitText(&data1->value.sValue, "number"); break; case T_STRING: strInitText(&data1->value.sValue, "string"); break; case T_BOOLEAN: strInitText(&data1->value.sValue, "boolean"); break; case T_NIL: strInitText(&data1->value.sValue, "nil"); break; default: errorFree(); return EINT; } data1->varType = T_STRING; break; // FUNKCE SUBSTRING case I_FSUBS: if(data1 != NULL && data2 != NULL && data3 != NULL) { if(data1->varType == T_STRING && data2->varType == T_NUMBER && data3->varType == T_NUMBER) { retData.varType = T_STRING; retData.hasValue = HAVE_VALUE; strInit(&retData.value.sValue); strSub(&data1->value.sValue,&retData.value.sValue,(int)data2->value.dValue,(int)data3->value.dValue); } else { data1->varType = T_NIL; data1->hasValue = 1; data1->value.bValue = 0; } } else { errorFree(); return EINT; } break; // FUNKCE FIND case I_FFIND: if(data2->varType == T_STRING && data3->varType == T_STRING) { if(data2->hasValue != 0 && data2->hasValue != 0) { int number = 0; if(data3->value.sValue.length == 0) { if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->value.dValue = number; data1->varType = T_NUMBER; data1->hasValue = HAVE_VALUE; break; } else number = boyerMooreSearch(&data2->value.sValue, &data3->value.sValue); if(data1->varType == T_STRING) strFree(&data1->value.sValue); if (number == 0) { data1->value.bValue = 0; data1->varType = T_BOOLEAN; data1->hasValue = HAVE_VALUE; } else { data1->value.dValue = number; data1->varType = T_NUMBER; data1->hasValue = HAVE_VALUE; } } else { errorFree(); return EINT; } } else { if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->varType = T_NIL; data1->hasValue = 1; data1->value.bValue = 0; } break; // FUNKCE SORT case I_FSORT: makeCopy(data1,&dataC); if(data3->varType == T_STRING) { dataC.varType = T_STRING; sort(&data3->value.sValue,&dataC.value.sValue); if(data1->varType == T_STRING) strFree(&data1->value.sValue); data1->varType = T_STRING; data1->hasValue = HAVE_VALUE; strInitText(&data1->value.sValue,dataC.value.sValue.str); } else { data1->varType = T_NIL; data1->hasValue = 1; data1->value.bValue = 0; } if(dataC.varType == T_STRING) strFree(&dataC.value.sValue); break; // PUSH case I_PUSH: if(data2 != NULL) { // ked pushujeme premenne pre funkciu potrebujeme data1 data2 // pre originalny nazov parametru pushData.varType = data2->varType; strInitText(&pushData.varKey,data1->varKey.str); if(data2->varType == T_STRING) strInitText(&pushData.value.sValue,data2->value.sValue.str); else if(data2->varType == T_NIL) pushData.value.bValue = 0; else if(data2->varType == T_BOOLEAN) pushData.value.bValue = data2->value.bValue; else if(data2->varType == T_NUMBER) pushData.value.dValue = data2->value.dValue; pushData.hasValue = HAVE_VALUE; hListInsert(&list2, &pushData, S_VAR); strFree(&pushData.varKey); if(pushData.varType == T_STRING) strFree(&pushData.value.sValue); } // push lokalnej premennej else if(data1 != NULL) hListInsert(&list2, data1, S_VAR); break; // RETURN case I_RETURN: retData.varType = data1->varType; retData.hasValue = data1->hasValue; switch(retData.varType) { case T_STRING: strInitText(&retData.value.sValue, data1->value.sValue.str); break; case T_NUMBER: retData.value.dValue = data1->value.dValue; break; case T_BOOLEAN: retData.value.bValue = data1->value.bValue; break; case T_NIL: retData.value.bValue = 0; break; } hListClearToLab(&list2); listGoto(iList,jStackPop(&jStack)); break; // KONEC PROGRAMU case I_END: errorFree(); return 0; break; } // ukazatele na NULL data1 = NULL; data2 = NULL; data3 = NULL; var = NULL; // nacteme dalsi instrukci listNext(iList); } return EIOK; }