Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into task5
Browse files Browse the repository at this point in the history
  • Loading branch information
idterk authored Dec 21, 2023
2 parents b9df6d2 + 0069a62 commit 359dd2f
Show file tree
Hide file tree
Showing 14 changed files with 733 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
| 16 | [Рудецкий Евгений](https://github.com/RuuuuuD3) | [ii02416](trunk/ii02416) ||||||| | | 9|
| 17 | Супрунович Илья | [ii02417](trunk/ii02417) ||||| | | | | |
| 18 | [Сухаревич Дмитрий](https://github.com/SukharevichDmitry)|[ii02418](trunk/ii02418)|||||| | | | 7|
| 19 | [Терехов Николай](https://github.com/idterk) | [ii02419](trunk/ii02419) |||| || | | | 7|
| 19 | Терехов Николай | [ii02419](trunk/ii02419) |||| || | | | 8|
| 20 | Турубчук Екатерина | [ii02420](trunk/ii02420) ||||| | | | | |
| 21 | [Черник Владислав](https://github.com/fdlbro) | [ii02421](trunk/ii02421) ||||| | | | | 6|
| 22 | Штыхно Даниил | [ii02422](trunk/ii02422) |||||| | | | 7|
Expand Down
Binary file added trunk/ii02419/task_03/doc/laba3otis_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trunk/ii02419/task_03/doc/laba3otis_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trunk/ii02419/task_03/doc/laba3otis_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trunk/ii02419/task_03/doc/laba3otis_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trunk/ii02419/task_03/doc/laba3otis_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions trunk/ii02419/task_03/doc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<p align="center"> Министерство образования Республики Беларусь</p>
<p align="center">Учреждение образования</p>
<p align="center">“Брестский Государственный технический университет”</p>
<p align="center">Кафедра ИИТ</p>
<br><br><br><br><br><br><br>
<p align="center">Лабораторная работа №3</p>
<p align="center">По дисциплине “Общая теория интеллектуальных систем”</p>
<p align="center">Тема: “Разработка редактора графов”</p>
<br><br><br><br><br>
<p align="right">Выполнил:</p>
<p align="right">Студент 2 курса</p>
<p align="right">Группы ИИ-24</p>
<p align="right"> Терехов Н.А.</p>
<p align="right">Проверил:</p>
<p align="right">Иванюк Д. С.</p>
<br><br><br><br>
<p align="center">Брест 2023</p>


---
# Реализованные функции:
![laba3otis_1](laba3otis_1.png)
![laba3otis_2](laba3otis_2.png)
![laba3otis_3](laba3otis_3.png)
![laba3otis_4](laba3otis_4.png)
![laba3otis_5](laba3otis_5.png)
---
7 changes: 7 additions & 0 deletions trunk/ii02419/task_03/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.6)

project(LAB_03)

set(SOURCES main.cpp)

add_executable(MyOnlyExecutable ${SOURCES})
57 changes: 57 additions & 0 deletions trunk/ii02419/task_03/src/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Foundation
import UIKit

extension String {
func arrayStringToInt(content: [String]) -> [Int] {
var intArray: [Int] = []
for element in content {
intArray.append(Int(element) ?? 1)
}
return intArray
}
}
public func alertWithTextField(title: String,
message: String,
placeholder: String?,
handler: ((_ int: [Int], _ string: String) -> Void)?) -> UIViewController {
var peaksString: [String] = []
var peaksInt: [Int] = []
var name = String()
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addTextField { (textField: UITextField!) -> Void in
textField.placeholder = placeholder
}
let okey = UIAlertAction(title: "Ok", style: .default) { _ in
name = alert.textFields![0].text ?? ""
peaksString = (alert.textFields![0].text?.components(separatedBy: " "))!
peaksInt = peaksString.description.arrayStringToInt(content: peaksString)
if let handler = handler {
handler(peaksInt, name)
}
}
alert.addAction(okey)
return alert
}
public func actionSheet(titleForFirstAction: String,
titleForSecondAction: String,
closureForFirstAction: @escaping () -> Void,
closureForSecondAction: @escaping () -> Void) -> UIViewController {
let alert = UIAlertController(title: "Внимание", message: "Выберите действие", preferredStyle: .actionSheet)
let deletePeak = UIAlertAction(title: titleForFirstAction, style: .default) { _ in
closureForFirstAction()
}
let deleteEdge = UIAlertAction(title: titleForSecondAction, style: .default) { _ in
closureForSecondAction()
}
let cancel = UIAlertAction(title: "Отмена", style: .cancel)
alert.addAction(deletePeak)
alert.addAction(deleteEdge)
alert.addAction(cancel)
return alert
}
public func alert(title: String, message: String) -> UIViewController {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let okey = UIAlertAction(title: "OK", style: .default)
alert.addAction(okey)
return alert
}
31 changes: 31 additions & 0 deletions trunk/ii02419/task_03/src/InfoViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit

class InfoViewController: UIViewController {
@IBOutlet weak var numberOfEdgesLabel: UILabel!
@IBOutlet weak var numberOfPeaksLabel: UILabel!
@IBOutlet weak var multiplicityCurrentPeakLabel: UILabel!
@IBOutlet weak var multiplicityAllPeaksLabel: UILabel!
var numberOfPeaks = ""
var numberOfEdges = ""
var multiplicityAll = ""
var multiplicityCurrentPeak = ""
override func viewDidLoad() {
super.viewDidLoad()
numberOfPeaksLabel.text? += numberOfPeaks
numberOfEdgesLabel.text? += numberOfEdges
multiplicityAllPeaksLabel.text? += multiplicityAll
multiplicityCurrentPeakLabel.text? += multiplicityCurrentPeak
}
func getInfo(info: (Int, (Int, [Int])), peak: Int?) {
numberOfPeaks += String(info.0)
numberOfEdges += String(info.1.0)
for (index, element) in info.1.1.enumerated() {
multiplicityAll += String(index + 1) + ": " + String(element) + " "
}
guard let peak = peak else {
multiplicityCurrentPeak = "Вершина не выбрана"
return
}
multiplicityCurrentPeak += String(info.1.1[peak - 1])
}
}
116 changes: 116 additions & 0 deletions trunk/ii02419/task_03/src/StartViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// сделать проверку на дурака в textView(проверка на одну вершину и текст)
import UIKit

class StartViewController: UIViewController {
// MARK: - variables
public var peaks = Set<String>()
@IBOutlet weak var dataTextView: UITextView!
@IBOutlet weak var nameOfGraphTextField: UITextField!
@IBOutlet weak var doneButton: UIButton!
var isAddGraph = false
var currentGraph = 1
var allPeaks: [Int] = []
public var isPreview = true
var placeholderForTextView = """
Пример ввода
1 2
3 2
4 5
6 7
"""
var nameOfGraph = ""
override func viewDidLoad() {
super.viewDidLoad()
dataTextView.delegate = self
customTextView()
customButton()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
peaks.removeAll()
allPeaks.removeAll()
}
// кастомизация кнопки
private func customButton() {
doneButton.layer.cornerRadius = 15
}
// кастомизация textView
private func customTextView() {
dataTextView.layer.cornerRadius = 15
dataTextView.text = placeholderForTextView
}
// переход на новый view и передача данных
@IBAction func doneButtonTapped(_ sender: Any) {
countOfPeaks()
if isAddGraph {
if dataTextView.text == ""
|| dataTextView.text == placeholderForTextView {
let alert = alert(title: "Внимание", message: "Заполните все поля")
present(alert, animated: true, completion: nil)
} else if nameOfGraphTextField.text == "" {
nameOfGraph = "Graph\(currentGraph)"
}
nameOfGraph = nameOfGraphTextField.text ?? "Graph\(currentGraph)"
UserDefaults.standard.set(peaks.count, forKey: "peaksGraph\(currentGraph)")
UserDefaults.standard.set(allPeaks, forKey: "allPeaksGraph\(currentGraph)")
UserDefaults.standard.set(nameOfGraph, forKey: "nameOfGraph\(currentGraph)")
self.navigationController?.popViewController(animated: true)
} else {
if nameOfGraphTextField.text == ""
|| dataTextView.text == ""
|| dataTextView.text == placeholderForTextView {
let alert = alert(title: "Внимание", message: "Заполните все поля")
present(alert, animated: true, completion: nil)
} else if nameOfGraphTextField.text == "" {
nameOfGraph = "Graph\(currentGraph)"
}
nameOfGraph = nameOfGraphTextField.text ?? "Graph\(currentGraph)"
UserDefaults.standard.set(nameOfGraph, forKey: "nameOfGraph\(currentGraph)")
UserDefaults.standard.set(dataTextView.text, forKey: "data")
UserDefaults.standard.set(peaks.count, forKey: "peaks")
UserDefaults.standard.set(allPeaks, forKey: "allPeaks")
performSegue(withIdentifier: "detail", sender: self)
}
}
// скрытие клавиатуры
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
dataTextView.resignFirstResponder()
dataTextView.layer.shadowOpacity = 0
}
// подсчет вершин
public func countOfPeaks() {
var number = ""
for symbol in dataTextView.text {
if symbol != " " && symbol != "\n" {
number += String(symbol)
} else {
peaks.insert(number)
allPeaks.append(Int(number)! - 1)
number = ""
}
}
let str = dataTextView.text
guard let str = str else { return }
for (index, element) in str.enumerated() where index == str.count - 1 {
let char = String(element)
allPeaks.append(Int(char)! - 1)
peaks.insert(String(element))
}
}
func getData(value: Bool, currentGraph: Int) {
isAddGraph = value
self.currentGraph = currentGraph
}
}
extension StartViewController: UITextViewDelegate {
func textViewDidBeginEditing(_ textView: UITextView) {
if isPreview {
textView.text = ""
isPreview = false
}
dataTextView.layer.shadowColor = UIColor.black.cgColor
dataTextView.layer.shadowOpacity = 1.0
dataTextView.layer.shadowOffset = CGSize(width: 0, height: 0)
dataTextView.layer.shadowRadius = 15.0
}
}
Loading

0 comments on commit 359dd2f

Please sign in to comment.