当前位置:网站首页>Transfer guide printing system based on C language design
Transfer guide printing system based on C language design
2022-07-26 08:38:00 【biyezuopin】
be based on C Language designed transfer guide printing system
subject
The subway traffic network in Shanghai has basically taken shape , Many subways have been built , There are hundreds of sites , Now we need to build a transfer guide printing system , Through the starting station and terminal station , Print out the subway transfer guide , The content of the guide includes the starting station 、 Transfer Station 、 The terminal .
- Graphically display the subway network structure , It can dynamically add subway lines and stations .
- According to the starting station and terminal station , Show subway transfer guide .
- Show the riding path through the graphic boundary .
software function
In the comprehensive questions , Programming language and development framework are different from algorithm implementation problems . The programming language is changed to Swift, The development framework is changed to WWDC 2019[7] Released in SwiftUI.
In the algorithm implementation problem, the data structure of the graph and various operations have been basically realized , On the basis of this experience, the realization of algorithm function only requires the migration of code into programming language ,
Swift Is a highly expressive 、 modernization 、 Grammatically elegant static typology , So the migration is very simple , The amount of code is also reduced .
On the basis of migrating code , It also adds the writing of the shortest path algorithm , This algorithm returns the real shortest path of a series of coordinate pairs .
The focus of the whole procedure , Namely SwiftUI.
SwiftUI
SwiftUI It's a kind of declarative UI frame , Declarative makes the code synchronized with the world , An example is as follows , Above is the code ( It's simple ), Lower bound .
VStack Medium V representative Vertical, That's vertical .
HStack Medium H representative Horizontal, Namely flat .
Spacer It represents a very empty area .
The code under will display the two groups of words horizontally , Then organize them into vertical areas , It contains Spacer( The code of the corresponding color is consistent with the box selection area of the corresponding color , The box selection area is added for dynamic effect ).
struct ContentView: View {
var body:
some View {
VStack {
HStack {
Text(" I'm Wei Yuxiang ")
Text(" My student number is 1750222")
}
Spacer()
HStack {
Text(" I'm in Tongji University ")
Text(" My major is computer ")
}
}
}
}
User interaction
First , The app Put all the operations ( In addition to some operations through potential ) Are integrated into a floating menu bar , Households can grope , Simple and easy to understand . The floating menu bar can be displayed by 、 hide , This increases the screen rate .


Due to the particularity of the machine , Potential operation improves the user interaction experience very . The app Contains the map refers to the kneading and scaling potential , Single drag and drop to move the map potential . meanwhile , Long pressing a vertex will show or hide the site name represented by the vertex . Put the map slightly , It refers to dragging from any site , The dragged site is the site of the new site , The new site name is in the menu bar .


design idea
The app The design idea of is different from the design idea of algorithm realization problem , Not adopt MVC framework , Yes MVVM(Model View ViewModel) Design patterns . Its data communication mode is as follows .

among Model It's the whole data model , As a tool .ViewModel Is the abstract table of the whole view , It represents the whole view , At the same time, bind it to the components in the view by binding . Users can directly operate the view , The change of view changes the bound ViewModel The corresponding data in ,ViewModel The change of continues to View Enter synchronization .
SwiftUI As a declarative UI Cut... Is provided MVVM The tools needed are @Binding、@State、@ObservedObject etc. attributes. Quickly build through declarative syntax View, And will ViewModel Through these attributes Bound to the View in , individual app It's done. . In order to better explain this idea , Let's take an example .
struct ContentView: View {
@State var toggleIson = false
var body:
some View {
VStack {
Toggle(isOn: $toggleIson) {
Text(" According to the text ")
}
.padding()
if toggleIson { Text(" It's hard for me .. The computer is so tired ")}
}
}
}


Of this code ViewModel Namely @State var toggleIsOn: Bool This boolean variable , It has no Model. This variable passes through Toggle Designed in Binding Bound to the view , Toggle key on view (toggle) The change of will directly change the bound data , namely toggleIsOn This variable . When the switch key is green, the variable is true, When the switch key is gray, the variable is false. Whether this variable is true or false directly affects whether the word is obvious , From sync to this View. This is it. MVVM Data flow of Architecture .(SwiftUI in @State And @ObservedObject Same idea , but @ObservedObject It is more suitable for complete and relatively ViewModel, @State Suitable for Boolean variables and other data .)
data structure
The same as the algorithm implementation problem , Still use adjacency table . The reason for adopting adjacency table is that subway lines belong to sparse map , There is no direct connection between stations except the front and back stations , At the same time, consider the machine app Adjacency table adjacency matrix is adopted for storage requirements .
Algorithm design
The algorithm adopts non optimized Dijkstra Algorithm , The complexity is O(n2). Design ideas he , Introduction to reference algorithms [4].
App Design
Whole app Of Model Is the graph of adjacency table ;ViewModel It is to make Model And abstract the view . Here we mainly discuss View The design of the .
SwiftUI Everything cut in is a View, To be more precise, they all follow View This Agreement ,Swift It's a protocol oriented programming language [8]. These views are highly combinatorial , To define a view, you only need to follow the protocol and implement it var body: some View { get } that will do . So the whole app The design idea of is the combination of different plates : Explicit bounds 、 Menu selection 、 Metro Station 、 Subway lines ……
Logical structure and physical structure
Same as algorithm design problem , This is only about Model Data structure of .
Site
/// Model for a station struct Station { var name: String var position: CGPoint
static func distance(_ lhs: Self, _ rhs: Self) -> Double {
let deltaX = lhs.position.x - rhs.position.x let deltaY = lhs.position.y - rhs.position.y
return sqrt(Double(deltaX * deltaX + deltaY * deltaY))
}
} extension Station:
Codable {}
Two sites have two messages , Name and location , So it has these two properties . meanwhile , A static method is defined to calculate the distance between two points . final extension Make the site follow agreement , Then the outside JSON Data Guide .
Subway Map
/// Data model for subway graph struct SubwayGraph: Codable {
/// The vertex subscript and distance corresponding to the adjacent edge
struct ArcNode: Hashable, Codable {
var index:
Int var distance:
Double
}
private(set) var vertices = [Station]() private(set) var arcs = [Int: Set<ArcNode>]()
/// The site name to its subscript map
private(set) var stationToIndex = [String: Int]()
/// Coordinate pairs of starting point and ending point
struct StationPair: Codable {
var start:
CGPoint var destination:
CGPoint
}
/// Start and end coordinates of all lines
private(set) var subwayLines:
[StationPair] = []
// ...
}
The data structure of the subway map is similar to that of the map in the algorithm , The difference is , First, add distance Table distance , Secondly, add subwayLines This attribute lists the start and vertex of all connected edges , Then the view shows .
Development platform
summary
operating system :macOS Mojave 10.14.6
Programming language :Swift 5.1
Development framework :SwiftUI
compiler :Apple Swift
IDE:Xcode Version 11.0 beta 6 (11M392R) Running environment .
The above environment can be built and operated app, adopt Xcode Simulator. It can simulate various Apple equipment .
Other macOS Whether the executable program can be directly operated in the environment simulator Unknown .
release iOS 13、 release Xcode 11 It can be released directly build To iPhone、iPad On .
If you have any iOS 13 beta Version of the device can also directly make the above environment build.
SwiftUI Cross home platform , So it's time to app With a little modification, it can become macOS、tvOS、 watchOS Of app, The following is the source code directly added to the new tvOS The result after item .
because SwiftUI The layout system adapts to different OS, Therefore, the obvious effect is normal ( But some functions such as drag potential method make ).

The analysis of system operation results shows that the development tools have adopted Xcode Of beta edition . because SwiftUI I'm not old enough 3 individual , It will take some time for it to be officially put into production , Therefore, only the beta version of the relevant tool chain is available . meanwhile , Contained in the chain Swift 5.1 Version of the compiler has not been officially released . If yes Swift If you are interested, please refer to .
Overall, the beta version is still very good , Collapse rarely occurs . meanwhile Swift 5.1 Add SwiftUI It also enables the code to fly more .

Data acquisition
The data of the whole Shanghai subway station is mainly obtained through , After engraving
Convert it to JSON Pieces of .


This JSON The final operation is to initialize the station array from the starting point to the end point of each subway line .
let stationGroups:[[Station]] = load("subwayData.json")
Through this array, we can export to ViewModel in . For details, please refer to the source DataHandler.swift.
correctness
The subway route map can basically achieve the expected effect after the transformation from longitude and latitude to horizontal coordinates .

Now check the route from Jiading campus to Siping campus

You can see the clear red line in the figure , Long press the vertex to display the station name , It is found that the line meets the expectation .
Dynamically add vertices through sliding potential , First select the new site name in the menu , Then drag to the position you want to add , You can successfully and accurately add .

On this basis, add YuXiang Road Line to Changji East Road ( Dynamic adding circuit is one-way adding ).
Observe after adding lines YuXiang Road The shortest route to Tongji school station , The result is normal .
The yellow line of the subway here is deliberately displayed , You can actually pass a toggle Switch whether to display . The same is true for the shortest path , Both have great animation effects .


stability
emmm , just so so .10% About the probability app Will be inexplicable in the middle crash. But overall, the stability is considerable .
Fault tolerance can
From the input selectivity to avoid abnormal input . At the same time, if the user selects the vertex addition with the same name, it will not succeed , Because the data structure is based on the site name to distinguish sites , If the name is the same, the site method can distinguish . also , If the same circuit is added , Because adjacency points form a set , So inserting the same value into the set will not change the set , Therefore, the situation of adding lines repeatedly is avoided in the degree of data structure .
Version control system
In this development, it still makes Git[6] And GitHub.
Git There are also two ,Terminal、Xcode Integrate .


边栏推荐
- 2022 national vocational college skills competition "network security" competition question file upload penetration test answer flag
- Add in the registry right click to open in vscode
- Oracle 19C OCP 1z0-082 certification examination question bank (51-60)
- Spark persistence strategy_ Cache optimization
- Storage of drawings (refined version)
- Excel find duplicate lines
- Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
- Flutter upgrade 2.10
- Please tell me if there is any way to increase the write out rate when the Flink SQL client is in the sink table. When synchronizing through sink table
- Flutter custom player progress bar
猜你喜欢

6、 Pinda general permission system__ pd-tools-log

Why reserve a capacitor station on the clock output?

Foundry教程:使用多种方式编写可升级的智能合约(上)

基于C#实现的文件管理文件系统
![[time complexity, space complexity]](/img/f2/f82c7e0a6ab9f893023c2ddbac3431.png)
[time complexity, space complexity]

Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)

【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话

Mysql8 one master one slave +mycat2 read write separation

基于C语言设计的换乘指南打印系统

Matplotlib learning notes
随机推荐
基于C#实现的文件管理文件系统
23.9 application exit application exit
日常一记(11)--word公式输入任意矩阵
Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
Mysql/mariadb (Galera multi master mode) cluster construction
Logic of data warehouse zipper table
QT uses QSS to make a beautiful login interface (hand-in-hand teaching)
JS工具函数大全
QSS add resource file of QT
Inaccurate problem of flutter fijkplayer seekto
Flutter WebView three fingers rush or freeze the screen
Flutter custom player progress bar
Day 4 homework
Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
Take out brother is the biggest support in this society
Oracle 19C OCP 1z0-082 certification examination question bank (19-23)
Flutter upgrade 2.10
Problems caused by slivereappbar
Apple's tough new rule: third-party payment also requires a percentage, and developers lose a lot!
Summary of common skills