@@ -44,6 +44,152 @@ export class FileManager {
44
44
console.log(eventHistory);*/
45
45
}
46
46
47
+ loadString ( content ) {
48
+ this . isLoadingState = true ;
49
+
50
+ flipflop . splice ( 0 , flipflop . length ) ;
51
+ srLatch . splice ( 0 , srLatch . length ) ;
52
+ gate . splice ( 0 , gate . length ) ;
53
+ wireMng . wire . splice ( 0 , wireMng . wire . length ) ;
54
+ logicClock . splice ( 0 , logicClock . length ) ;
55
+ logicInput . splice ( 0 , logicInput . length ) ;
56
+ logicOutput . splice ( 0 , logicOutput . length ) ;
57
+ nodeList . splice ( 0 , nodeList . length ) ;
58
+
59
+ let contentFile = content ;
60
+ //console.log(contentFile);
61
+
62
+ // logic input
63
+ if ( 'logicInput' in JSON . parse ( contentFile ) ) {
64
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
65
+ let objectParsed = JSON . parse ( contentFile ) . logicInput [ i ] ;
66
+
67
+ if ( objectParsed == undefined ) break ;
68
+
69
+ console . log ( objectParsed ) ;
70
+ logicInput . push ( new LogicInput ( ) ) ;
71
+ Object . assign ( logicInput [ i ] , objectParsed ) ;
72
+ logicInput [ i ] . refreshNodes ( ) ;
73
+ }
74
+ }
75
+ // logic output
76
+ //console.log(logicOutput);
77
+ if ( 'logicOutput' in JSON . parse ( contentFile ) ) {
78
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
79
+ let objectParsed = JSON . parse ( contentFile ) . logicOutput [ i ] ;
80
+
81
+ if ( objectParsed == undefined ) break ;
82
+
83
+ console . log ( objectParsed ) ;
84
+ logicOutput . push ( new LogicOutput ( ) ) ;
85
+ Object . assign ( logicOutput [ i ] , objectParsed ) ;
86
+ logicOutput [ i ] . refreshNodes ( ) ;
87
+ }
88
+ }
89
+
90
+ if ( 'logicClock' in JSON . parse ( contentFile ) ) {
91
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
92
+ let objectParsed = JSON . parse ( contentFile ) . logicClock [ i ] ;
93
+
94
+ if ( objectParsed == undefined ) break ;
95
+
96
+ console . log ( objectParsed ) ;
97
+ logicClock . push ( new Clock ( ) ) ;
98
+ Object . assign ( logicClock [ i ] , objectParsed ) ;
99
+ logicClock [ i ] . refreshNodes ( ) ;
100
+ }
101
+ }
102
+
103
+ if ( 'gate' in JSON . parse ( contentFile ) ) {
104
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
105
+ let objectParsed = JSON . parse ( contentFile ) . gate [ i ] ;
106
+
107
+ if ( objectParsed == undefined ) break ;
108
+
109
+ console . log ( objectParsed ) ;
110
+ gate . push ( new Gate ( JSON . parse ( contentFile ) . gate [ i ] . strType ) ) ;
111
+ Object . assign ( gate [ i ] , objectParsed ) ;
112
+ gate [ i ] . refreshNodes ( ) ;
113
+ }
114
+ }
115
+
116
+ if ( 'srLatch' in JSON . parse ( contentFile ) ) {
117
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
118
+ let objectParsed = JSON . parse ( contentFile ) . srLatch [ i ] ;
119
+
120
+ if ( objectParsed == undefined ) break ;
121
+
122
+ console . log ( objectParsed ) ;
123
+
124
+ switch ( JSON . parse ( contentFile ) . srLatch [ i ] . type ) {
125
+ case IC_type . SR_LATCH_ASYNC :
126
+ srLatch . push (
127
+ new SR_LatchAsync (
128
+ JSON . parse ( contentFile ) . srLatch [ i ] . gateType ,
129
+ JSON . parse ( contentFile ) . srLatch [ i ] . stabilize ,
130
+ ) ,
131
+ ) ;
132
+ break ;
133
+ case IC_type . SR_LATCH_SYNC :
134
+ srLatch . push (
135
+ new SR_LatchSync (
136
+ JSON . parse ( contentFile ) . srLatch [ i ] . gateType ,
137
+ JSON . parse ( contentFile ) . srLatch [ i ] . stabilize ,
138
+ ) ,
139
+ ) ;
140
+ break ;
141
+ }
142
+ Object . assign ( srLatch [ i ] , objectParsed ) ;
143
+ srLatch [ i ] . refreshNodes ( ) ;
144
+ }
145
+ }
146
+
147
+ if ( 'flipflop' in JSON . parse ( contentFile ) ) {
148
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
149
+ let objectParsed = JSON . parse ( contentFile ) . flipflop [ i ] ;
150
+
151
+ if ( objectParsed == undefined ) break ;
152
+
153
+ console . log ( objectParsed ) ;
154
+
155
+ switch ( JSON . parse ( contentFile ) . flipflop [ i ] . type ) {
156
+ case IC_type . FF_D_SINGLE :
157
+ flipflop . push (
158
+ new FF_D_Single ( JSON . parse ( contentFile ) . flipflop [ i ] . type ) ,
159
+ ) ;
160
+ break ;
161
+ case IC_type . FF_D_MASTERSLAVE :
162
+ flipflop . push (
163
+ new FF_D_MasterSlave ( JSON . parse ( contentFile ) . flipflop [ i ] . type ) ,
164
+ ) ;
165
+ break ;
166
+ case IC_type . FF_T :
167
+ flipflop . push ( new FF_T ( JSON . parse ( contentFile ) . flipflop [ i ] . type ) ) ;
168
+ break ;
169
+ case IC_type . FF_JK :
170
+ flipflop . push ( new FF_JK ( JSON . parse ( contentFile ) . flipflop [ i ] . type ) ) ;
171
+ break ;
172
+ }
173
+ Object . assign ( flipflop [ i ] , objectParsed ) ;
174
+ flipflop [ i ] . refreshNodes ( ) ;
175
+ }
176
+ }
177
+
178
+ if ( 'wire' in JSON . parse ( contentFile ) ) {
179
+ for ( let i = 0 ; i < contentFile . length ; i ++ ) {
180
+ let objectParsed = JSON . parse ( contentFile ) . wire [ i ] ;
181
+
182
+ if ( objectParsed == undefined ) break ;
183
+
184
+ console . log ( objectParsed ) ;
185
+
186
+ wireMng . addNode ( nodeList [ objectParsed . startID ] ) ;
187
+ wireMng . addNode ( nodeList [ objectParsed . endID ] ) ;
188
+ //Object.assign(gate[i], objectParsed);
189
+ }
190
+ }
191
+ }
192
+
47
193
/**
48
194
* @todo TODO
49
195
*/
0 commit comments