-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib1.c
314 lines (304 loc) · 15 KB
/
lib1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//***********************************************************//
// [ Source Code ] //
// Institution : Institut Teknologi Bandung
// Name : Patrick Ryan Wijaya
// File Name : lib1.c
// Dependency : lib1.h
// Description:
// Source Code library untuk layouting manual dan tampilan
// hasil layouting Manual
// // Status:
// 1. Patrick Ryan Wijaya - 13217027 : Perancangan source code
//***********************************************************//
#include "lib1.h"
//asumsi kaki komponen hanya bisa disusun secara horizontal dan vertikal, tidak bisa secara diagonal untuk mempermudah perhitungan jarak antar kaki komponen.
void interfaceLayout(component_t *c,char matrix[40][40][6], int baris, int kolom){ //Interface Input dari Layouting manual
char coma;
int i,j;
printf("Isi 'q' atau 'Q' untuk kembali ke menu \n");
while(((*c).name[0] != 'Q') && ((*c).name[0] != 'q')) //Kondisi terminasi saat input Q atau q
{
printf("Pilih Komponen (R,C,T,J): ");
scanf("%s",(*c).name);
if((*c).name[0]== 'R'){ //Saat dipilih komponen resistor
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
while((((*c).koor1.x>baris) || ((*c).koor1.y>kolom) || ((*c).koor2.x>baris) || ((*c).koor2.y>kolom)) //validasi awal input pengguna
|| (((*c).koor1.x != (*c).koor2.x) && ((*c).koor1.y != (*c).koor2.y)) || (((*c).koor1.x == (*c).koor2.x) && ((*c).koor1.y == (*c).koor2.y)))
{
printf("Input komponen pada PCB tidak valid!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.x == (*c).koor2.x) && (abs((*c).koor1.y-(*c).koor2.y)<4)) //Validasi dengan kondisi tertentu
{
printf("Jarak Horizontal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.y == (*c).koor2.y) && (abs((*c).koor1.x-(*c).koor2.x)<4))
{
printf("Jarak vertikal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while((matrix[(*c).koor1.x][(*c).koor1.y][1]!= '\0') || (matrix[(*c).koor2.x][(*c).koor2.y][1] != '\0') ) //Pengecekan koordinar sudah diisi atau belum
{
printf("SUDAH TERISI!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
strcpy(matrix[(*c).koor1.x][(*c).koor1.y],(*c).name);
strcpy(matrix[(*c).koor2.x][(*c).koor2.y],(*c).name);
}
else if((*c).name[0]== 'C'){ //Dipilih komponen kapasitor
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
while((((*c).koor1.x>baris) || ((*c).koor1.y>kolom) || ((*c).koor2.x>baris) || ((*c).koor2.y>kolom)) //Validasi awal input pengguna
|| (((*c).koor1.x != (*c).koor2.x) && ((*c).koor1.y != (*c).koor2.y)) || (((*c).koor1.x == (*c).koor2.x) && ((*c).koor1.y == (*c).koor2.y)))
{
printf("Input komponen pada PCB tidak valid!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.x == (*c).koor2.x) && (abs((*c).koor1.y-(*c).koor2.y)<2)) //Validasi dengan kondisi tertentu
{
printf("Jarak Horizontal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.y == (*c).koor2.y) && (abs((*c).koor1.x-(*c).koor2.x)<2))
{
printf("Jarak vertikal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while((matrix[(*c).koor1.x][(*c).koor1.y][1]!= '\0') || (matrix[(*c).koor2.x][(*c).koor2.y][1]!= '\0') ) //Pengecekan apakah posisi sudah diisi atau belum
{
printf("SUDAH TERISI!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
strcpy(matrix[(*c).koor1.x][(*c).koor1.y],(*c).name);
strcpy(matrix[(*c).koor2.x][(*c).koor2.y],(*c).name);
}
else if((*c).name[0]== 'J'){ //Jika dipilih Komponen Jumper
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
while((((*c).koor1.x>baris) || ((*c).koor1.y>kolom) || ((*c).koor2.x>baris) || ((*c).koor2.y>kolom)) //Validasi awal input pengguna
|| (((*c).koor1.x != (*c).koor2.x) && ((*c).koor1.y != (*c).koor2.y)) || (((*c).koor1.x == (*c).koor2.x) && ((*c).koor1.y == (*c).koor2.y)))
{
printf("Input komponen pada PCB tidak valid!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.x == (*c).koor2.x) && (abs((*c).koor1.y-(*c).koor2.y)<1)) //Validasi dengan kondisi tertentu
{
printf("Jarak Horizontal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while(((*c).koor1.y == (*c).koor2.y) && (abs((*c).koor1.x-(*c).koor2.x)<1))
{
printf("Jarak vertikal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
while((matrix[(*c).koor1.x][(*c).koor1.y][1]!= '\0') || (matrix[(*c).koor2.x][(*c).koor2.y][1]!= '\0') ) //Mengecek apakah koordinat sudah terisi sebelumnya
{
printf("SUDAH TERISI!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
}
strcpy(matrix[(*c).koor1.x][(*c).koor1.y],(*c).name);
strcpy(matrix[(*c).koor2.x][(*c).koor2.y],(*c).name);
}
else if((*c).name[0]== 'T'){ //Jika dipilih komponen BJT
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
while(
(((*c).koor1.x>baris) || ((*c).koor1.y>kolom) || ((*c).koor2.x>baris) || ((*c).koor2.y>kolom) || ((*c).koor3.x>baris) || ((*c).koor3.y>kolom))
|| (((*c).koor1.x != (*c).koor2.x) && ((*c).koor1.y != (*c).koor2.y) && ((*c).koor1.x != (*c).koor3.x) && ((*c).koor1.y != (*c).koor3.y) && ((*c).koor2.x != (*c).koor3.x) && ((*c).koor2.y != (*c).koor3.y))
|| ((((*c).koor1.x == (*c).koor2.x) && ((*c).koor1.y == (*c).koor2.y)) || (((*c).koor1.x == (*c).koor3.x) && ((*c).koor1.y == (*c).koor3.y)) || (((*c).koor2.x == (*c).koor3.x) && ((*c).koor2.y == (*c).koor3.y)))
)//Validasi awal input User
{
printf("Input komponen pada PCB tidak valid!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
while((((*c).koor1.x == (*c).koor2.x) && ((*c).koor1.x == (*c).koor3.x) && ((abs((*c).koor1.y-(*c).koor2.y)<2)||(abs((*c).koor2.y-(*c).koor3.y)<2)))) //Pengecekan input user pada kondisi tertentu
{
printf("Jarak Horizontal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
while((((*c).koor1.x == (*c).koor2.x) && ((*c).koor2.y == (*c).koor3.y) && ((abs((*c).koor1.y-(*c).koor2.y)<2)||(abs((*c).koor2.x-(*c).koor3.x)<2))))
{
printf("Jarak komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
while((((*c).koor1.y == (*c).koor2.y) && ((*c).koor1.y == (*c).koor3.y) && ((abs((*c).koor1.x-(*c).koor2.x)<2)||(abs((*c).koor2.x-(*c).koor3.x)<2))))
{
printf("Jarak vertikal komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
while((((*c).koor1.y == (*c).koor2.y) && ((*c).koor2.x == (*c).koor3.x) && ((abs((*c).koor1.x-(*c).koor2.x)<2)||(abs((*c).koor2.y-(*c).koor3.y)<2))))
{
printf("Jarak antar komponen tidak sesuai!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
while((matrix[(*c).koor1.x][(*c).koor1.y][1]!= '\0') || (matrix[(*c).koor2.x][(*c).koor2.y][1] != '\0') || (matrix[(*c).koor3.x][(*c).koor3.y][1] != '\0') ) //Pengecekan apakah Koordinat
//sudah terisi
{
printf("SUDAH TERISI!\n");
printf("Koordinat kaki 1: ");
scanf("%d%c%d",&(*c).koor1.x,&coma,&(*c).koor1.y);
printf("Koordinat kaki 2: ");
scanf("%d%c%d",&(*c).koor2.x,&coma,&(*c).koor2.y);
printf("Koordinat kaki 3: ");
scanf("%d%c%d",&(*c).koor3.x,&coma,&(*c).koor3.y);
}
strcpy(matrix[(*c).koor1.x][(*c).koor1.y],(*c).name); //Memasukkan Komponen tervalidasi ke Array 3 Dimensi
strcpy(matrix[(*c).koor2.x][(*c).koor2.y],(*c).name);
strcpy(matrix[(*c).koor3.x][(*c).koor3.y],(*c).name);
}
}
}
void printMatrix(char matr[40][40][6], int row, int col){ //Prosedur Menampilkan Array hasil Layouting Manual
int i,j,k;
for(k = 0; k<= col; k++) {
printf("%d\t", k);
}
printf("\n");
for (i=1;i<=row;i++){
printf("%d\t", i);
for (j=1;j<=col;j++){
printf("%s\t",matr[i][j]);
}
printf("\n");
}
printf("\n");
}
void loadLayout(char PCB_layout[40][40][6],int PCB_lebar,int PCB_panjang){
FILE *file1;
FILE *file2;
int i,j,k,lebar;
char baca_layout[40][100];
char nama_file[50];
int index_arr, idx, baris, kolom;
file1 = fopen("FILTERRCLAYOUT.csv","r");
//check if the file pointer is null
lebar=0;
if (file1 == NULL){
printf("File tidak dapat dibuka");
}
else {
while(fgets(baca_layout[lebar],50,file1) != NULL){
lebar = lebar+1;
}
}
fclose(file1);
for(i=0;i<40;i++){
for(j=0;j<40;j++){
strcpy(PCB_layout[i][j]," ");
}
}
i=0; baris=0; index_arr =0;
while(i<lebar){
kolom =0;idx=0;
while(baca_layout[i][idx]!='\n'){
if(baca_layout[i][idx]==' '){
PCB_layout[baris][kolom][index_arr]=' ';
//printf("(%d,%d,%d) %c\n", baris,kolom,index_arr,PCB_layout[baris][kolom][index_arr]);
}
else if(baca_layout[i][idx]!=',' ){
PCB_layout[baris][kolom][index_arr]=baca_layout[i][idx];
//printf("\n%s\n", PCB_layout[0][2]);
//printf("(%d,%d,%d) %c\n", baris,kolom,index_arr,PCB_layout[baris][kolom][index_arr]);
index_arr++;
}
else if(baca_layout[i][idx]==','){
//printf("\n%s\n", PCB_layout[0][2]);
index_arr=0;
kolom++;
}
//printf("\n%s\n", PCB_layout[0][2]);
idx++;
}
//printf("\n%s\n", PCB_layout[0][2]);
baris++;
i++;
}
kolom = PCB_panjang;
baris = PCB_lebar;
//ngeprint
for(k = 0; k<=kolom; k++) {
printf("%d\t", k);
}
printf("\n");
for(i=1;i<=baris;i++){
printf("%d\t", i);
for(j=0;j<=kolom;j++){
printf("%s\t",PCB_layout[i-1][j]);
}
printf("\n");
}
printf("\n");
}