This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
733 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.