1 | /*
|
---|
2 | * TOPPERS/ECNL Prototyping tool
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
11 | * スコード中に含まれていること.
|
---|
12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
15 | * の無保証規定を掲載すること.
|
---|
16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
18 | * と.
|
---|
19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
22 | * 報告すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
27 | * 免責すること.
|
---|
28 | *
|
---|
29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
33 | * の責任を負わない.
|
---|
34 | *
|
---|
35 | * @(#) $Id: EObjectWorkspace.cs 287 2017-05-05 14:22:23Z coas-nagasima $
|
---|
36 | */
|
---|
37 | using System;
|
---|
38 | using System.Collections.Generic;
|
---|
39 | using System.Linq;
|
---|
40 | using System.Text;
|
---|
41 | using Bridge;
|
---|
42 | using Bridge.Html5;
|
---|
43 | using Bridge.jQuery2;
|
---|
44 |
|
---|
45 | namespace WebMrbc
|
---|
46 | {
|
---|
47 | internal class EObjectWorkspace : IClassWorkspace
|
---|
48 | {
|
---|
49 | public JsonObjectInfo eobject;
|
---|
50 | private Workspace workspace;
|
---|
51 | BlocklyView view;
|
---|
52 | Action<bool> callback;
|
---|
53 | protected Ruby _RubyCode;
|
---|
54 |
|
---|
55 | public string Identifier { get { return view.Identifier; } }
|
---|
56 | public Workspace Workspace { get { return workspace; } }
|
---|
57 | public BlocklyView View { get { return view; } }
|
---|
58 | public Ruby RubyCode { get { return _RubyCode; } }
|
---|
59 |
|
---|
60 | public EObjectWorkspace(BlocklyView view, JsonObjectInfo eobject)
|
---|
61 | {
|
---|
62 | this.view = view;
|
---|
63 | this.eobject = eobject;
|
---|
64 | workspace = view.Init();
|
---|
65 |
|
---|
66 | view.FlyoutCategoryHandlers.Add("ECHONET_LITE_PROPERTY", FlyoutCategory);
|
---|
67 |
|
---|
68 | UpdateInitialBlock();
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected void UpdateInitialBlock()
|
---|
72 | {
|
---|
73 | var blocks = Workspace.getTopBlocks(false);
|
---|
74 | foreach (var b in blocks) {
|
---|
75 | if ((b.type == ENodeInitializeBlock.type_name)
|
---|
76 | || (b.type == EObjectInitializeBlock.type_name)) {
|
---|
77 | b.dispose(false);
|
---|
78 | continue;
|
---|
79 | }
|
---|
80 |
|
---|
81 | if ((b.type == EPropertyFixLenBlock.type_name)
|
---|
82 | || (b.type == EPropertyVarLenBlock.type_name)) {
|
---|
83 | ((dynamic)b).InitPropertyInfo(this);
|
---|
84 | continue;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | var xml = Document.CreateElement("xml");
|
---|
89 | var block = Document.CreateElement("block");
|
---|
90 | xml.AppendChild(block);
|
---|
91 |
|
---|
92 | if ((eobject.type.classGroup.classGroupCode == 0x0E)
|
---|
93 | && (eobject.type.classCode == 0xF0))
|
---|
94 | block.SetAttribute("type", ENodeInitializeBlock.type_name);
|
---|
95 | else
|
---|
96 | block.SetAttribute("type", EObjectInitializeBlock.type_name);
|
---|
97 |
|
---|
98 | var statement = Document.CreateElement("statement");
|
---|
99 | statement.SetAttribute("name", "DO");
|
---|
100 | block.AppendChild(statement);
|
---|
101 |
|
---|
102 | var prev = (Element)null;
|
---|
103 | foreach (var pi in eobject.properties) {
|
---|
104 | if (CodeGenerator.IsExtractProperty(pi))
|
---|
105 | continue;
|
---|
106 |
|
---|
107 | var vset = Document.CreateElement("block");
|
---|
108 | vset.SetAttribute("type", "variables_set");
|
---|
109 |
|
---|
110 | var field = Document.CreateElement("field");
|
---|
111 | field.SetAttribute("name", "VAR");
|
---|
112 | field.AppendChild(Document.CreateTextNode(CodeGenerator.GetPropertyIdentifier(pi)));
|
---|
113 | vset.AppendChild(field);
|
---|
114 |
|
---|
115 | var value = Document.CreateElement("value");
|
---|
116 | value.SetAttribute("name", "VALUE");
|
---|
117 | vset.AppendChild(value);
|
---|
118 |
|
---|
119 | var text = Document.CreateElement("shadow");
|
---|
120 | text.SetAttribute("type", "text");
|
---|
121 | value.AppendChild(text);
|
---|
122 |
|
---|
123 | field = Document.CreateElement("field");
|
---|
124 | field.SetAttribute("name", "TEXT");
|
---|
125 | var body = new StringBuilder();
|
---|
126 | GetInitialValue(body, pi, pi.valueDescription, false);
|
---|
127 | field.AppendChild(Document.CreateTextNode(body.ToString()));
|
---|
128 | text.AppendChild(field);
|
---|
129 |
|
---|
130 | if (prev != null) {
|
---|
131 | var next = Document.CreateElement("next");
|
---|
132 | next.AppendChild(vset);
|
---|
133 | prev.AppendChild(next);
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | statement.AppendChild(vset);
|
---|
137 | }
|
---|
138 | prev = vset;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Blockly.Xml.domToWorkspace(xml, Workspace);
|
---|
142 | }
|
---|
143 |
|
---|
144 | private void GetInitialValue(StringBuilder body, JsonFieldInfo emi, string valRng, bool recursive)
|
---|
145 | {
|
---|
146 | if (emi.type == "manufacturer_code_t") {
|
---|
147 | body.Append("#{$MAKER_CODE}");
|
---|
148 | return;
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (emi.type == "version_information_t") {
|
---|
152 | body.Append("\\x01\\x0A\\x01\\x00");
|
---|
153 | return;
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (emi.type == "standard_version_information_t") {
|
---|
157 | body.Append("\\x00\\x00C\\x00");
|
---|
158 | return;
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (emi.primitive) {
|
---|
162 | int count = emi.arrayCount;
|
---|
163 | if (count == 0) {
|
---|
164 | body.Append(CodeGenerator.GetInitialValue(valRng, emi));
|
---|
165 | }
|
---|
166 | else {
|
---|
167 | body.Append("");
|
---|
168 | for (int i = 0; i < count; i++) {
|
---|
169 | body.Append(CodeGenerator.GetInitialValue(valRng, emi));
|
---|
170 | }
|
---|
171 | body.Append("");
|
---|
172 | }
|
---|
173 | }
|
---|
174 | else if (emi.fields != null && emi.fields.Length > 0) {
|
---|
175 | foreach (var efi in emi.fields) {
|
---|
176 | GetInitialValue(body, efi, efi.valueDescription, true);
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | public virtual string GetImageUrl()
|
---|
182 | {
|
---|
183 | return "img/no_image.png";
|
---|
184 | }
|
---|
185 |
|
---|
186 | public virtual bool IsPreset()
|
---|
187 | {
|
---|
188 | return false;
|
---|
189 | }
|
---|
190 |
|
---|
191 | public virtual string ToCode(string filename)
|
---|
192 | {
|
---|
193 | if (eobject == null)
|
---|
194 | return "";
|
---|
195 |
|
---|
196 | _RubyCode = new Ruby(filename);
|
---|
197 | _RubyCode.init(Workspace);
|
---|
198 | var result = _RubyCode.defineEObject(eobject, workspace);
|
---|
199 | view.Changed = false;
|
---|
200 | return result;
|
---|
201 | }
|
---|
202 |
|
---|
203 | //Element ele;
|
---|
204 |
|
---|
205 | public virtual void Activate()
|
---|
206 | {
|
---|
207 | //ele = Blockly.Xml.workspaceToDom(workspace);
|
---|
208 | }
|
---|
209 |
|
---|
210 | public virtual void Inactivate()
|
---|
211 | {
|
---|
212 | //workspace.clear();
|
---|
213 | //Blockly.Xml.domToWorkspace(ele, workspace);
|
---|
214 | }
|
---|
215 |
|
---|
216 | public void ReloadToolbox(HTMLElement toolbox)
|
---|
217 | {
|
---|
218 | toolbox.AppendChild(Document.CreateElement("sep"));
|
---|
219 | var xml = jQuery.ParseXML(App.ArduinoToolbox);
|
---|
220 | var categories = xml.ChildNodes[0];
|
---|
221 | foreach (var item in categories.ChildNodes) {
|
---|
222 | if (item.NodeName != "category")
|
---|
223 | continue;
|
---|
224 | toolbox.AppendChild(item);
|
---|
225 | }
|
---|
226 |
|
---|
227 | toolbox.AppendChild(Document.CreateElement("sep"));
|
---|
228 | xml = jQuery.ParseXML(App.EcnlToolbox);
|
---|
229 | categories = xml.ChildNodes[0];
|
---|
230 | foreach (var item in categories.ChildNodes) {
|
---|
231 | if (item.NodeName != "category")
|
---|
232 | continue;
|
---|
233 | toolbox.AppendChild(item);
|
---|
234 | }
|
---|
235 |
|
---|
236 | var category = Document.CreateElement("category");
|
---|
237 | category.SetAttribute("name", "ECHONET Lite Property");
|
---|
238 | category.SetAttribute("custom", "ECHONET_LITE_PROPERTY");
|
---|
239 | category.SetAttribute("colour", "230");
|
---|
240 | toolbox.AppendChild(category);
|
---|
241 | }
|
---|
242 |
|
---|
243 | public EPropertyBlock[] allEProperties(Workspace root)
|
---|
244 | {
|
---|
245 | var blocks = root.getAllBlocks();
|
---|
246 | var eproperties = new EPropertyBlock[0];
|
---|
247 | for (var i = 0; i < blocks.Length; i++) {
|
---|
248 | var b = blocks[i];
|
---|
249 | if ((b.type == EPropertyFixLenBlock.type_name)
|
---|
250 | || (b.type == EPropertyVarLenBlock.type_name)) {
|
---|
251 | eproperties.Push(b);
|
---|
252 | }
|
---|
253 | }
|
---|
254 | return eproperties;
|
---|
255 | }
|
---|
256 |
|
---|
257 | private int procTupleComparator_(Tuple<string, byte, bool> ta, Tuple<string, byte, bool> tb)
|
---|
258 | {
|
---|
259 | return ta.Item2 - tb.Item2;
|
---|
260 | }
|
---|
261 |
|
---|
262 | private Element[] FlyoutCategory(Workspace workspace)
|
---|
263 | {
|
---|
264 | var xmlList = new Element[0];
|
---|
265 | var properties = allEProperties(workspace);
|
---|
266 |
|
---|
267 | foreach (var pi in eobject.properties) {
|
---|
268 | if (CodeGenerator.IsExtractProperty(pi))
|
---|
269 | continue;
|
---|
270 |
|
---|
271 | bool exist = false;
|
---|
272 | foreach (var p in from p in properties where p.PropertyCode == pi.propertyCode select p) {
|
---|
273 | exist = true;
|
---|
274 | break;
|
---|
275 | }
|
---|
276 | if (exist)
|
---|
277 | continue;
|
---|
278 |
|
---|
279 | bool varlen = pi.access.Contains("VARIABLE");
|
---|
280 | string identifier = CodeGenerator.GetPropertyIdentifier(pi);
|
---|
281 | ValueRange valueRange;
|
---|
282 | if (!CodeGenerator.HasPropSetter(pi, out valueRange))
|
---|
283 | valueRange = null;
|
---|
284 |
|
---|
285 | var block = Document.CreateElement("block");
|
---|
286 | if (varlen)
|
---|
287 | block.SetAttribute("type", EPropertyVarLenBlock.type_name);
|
---|
288 | else
|
---|
289 | block.SetAttribute("type", EPropertyFixLenBlock.type_name);
|
---|
290 |
|
---|
291 | var field = Document.CreateElement("field");
|
---|
292 | field.SetAttribute("name", "IDENTIFIER");
|
---|
293 | field.AppendChild(Document.CreateTextNode(identifier));
|
---|
294 | block.AppendChild(field);
|
---|
295 |
|
---|
296 | field = Document.CreateElement("field");
|
---|
297 | field.SetAttribute("name", "DESCRIPTION");
|
---|
298 | field.AppendChild(Document.CreateTextNode(pi.description));
|
---|
299 | block.AppendChild(field);
|
---|
300 |
|
---|
301 | field = Document.CreateElement("field");
|
---|
302 | field.SetAttribute("name", "PROPERTY_CODE");
|
---|
303 | field.AppendChild(Document.CreateTextNode(pi.propertyCode.ToString("X2")));
|
---|
304 | block.AppendChild(field);
|
---|
305 |
|
---|
306 | field = Document.CreateElement("field");
|
---|
307 | field.SetAttribute("name", "PROPERTY_SIZE");
|
---|
308 | field.AppendChild(Document.CreateTextNode(pi.size.ToString()));
|
---|
309 | block.AppendChild(field);
|
---|
310 |
|
---|
311 | xmlList.Push(block);
|
---|
312 |
|
---|
313 | // プロパティが可変長の場合
|
---|
314 | if (varlen) {
|
---|
315 | {
|
---|
316 | var statement = Document.CreateElement("statement");
|
---|
317 | statement.SetAttribute("name", "SET");
|
---|
318 | block.AppendChild(statement);
|
---|
319 |
|
---|
320 | var ifBlock = CreateSizeCheckBlocks();
|
---|
321 | statement.AppendChild(ifBlock);
|
---|
322 |
|
---|
323 | var next = Document.CreateElement("next");
|
---|
324 | ifBlock.AppendChild(next);
|
---|
325 |
|
---|
326 | if (pi.access.Contains("ANNOUNCE")) {
|
---|
327 | Element annoBlock = CreateAnnoCheck();
|
---|
328 | next.AppendChild(annoBlock);
|
---|
329 |
|
---|
330 | next = Document.CreateElement("next");
|
---|
331 | annoBlock.AppendChild(next);
|
---|
332 | }
|
---|
333 |
|
---|
334 | Element setBlock = null;
|
---|
335 | if (valueRange != null) {
|
---|
336 | setBlock = CreateSetStatement(valueRange);
|
---|
337 | }
|
---|
338 | else {
|
---|
339 | setBlock = Document.CreateElement("block");
|
---|
340 | setBlock.SetAttribute("type", EcnlSaveReceivedPropertyBlock.type_name);
|
---|
341 | }
|
---|
342 |
|
---|
343 | if (setBlock != null) {
|
---|
344 | next.AppendChild(setBlock);
|
---|
345 | }
|
---|
346 | }
|
---|
347 |
|
---|
348 | {
|
---|
349 | var value = Document.CreateElement("value");
|
---|
350 | value.SetAttribute("name", "SET_RET");
|
---|
351 | block.AppendChild(value);
|
---|
352 |
|
---|
353 | var subblock = Document.CreateElement("block");
|
---|
354 | subblock.SetAttribute("type", EcnlGetPropertyInfoBlock.type_name);
|
---|
355 | value.AppendChild(subblock);
|
---|
356 |
|
---|
357 | field = Document.CreateElement("field");
|
---|
358 | field.SetAttribute("name", "MEMBER");
|
---|
359 | field.AppendChild(Document.CreateTextNode("sz"));
|
---|
360 | subblock.AppendChild(field);
|
---|
361 | }
|
---|
362 | }
|
---|
363 | // プロパティが固定長の場合
|
---|
364 | else if ((valueRange == null) || ((valueRange.Values.Length == 0) && (valueRange.Ranges.Length == 0))) {
|
---|
365 | var mutation = Document.CreateElement("mutation");
|
---|
366 | mutation.SetAttribute("property_code", pi.propertyCode.ToString("X2"));
|
---|
367 | mutation.SetAttribute("identifier", identifier);
|
---|
368 | mutation.SetAttribute("description", pi.description);
|
---|
369 | mutation.SetAttribute("property_size", pi.size.ToString());
|
---|
370 | mutation.SetAttribute("default", "1");
|
---|
371 | mutation.SetAttribute("user_getter", "1");
|
---|
372 | block.AppendChild(mutation);
|
---|
373 |
|
---|
374 | Element setBlock = null;
|
---|
375 | switch (pi.propertyCode) {
|
---|
376 | // 現在時刻
|
---|
377 | case 0x97:
|
---|
378 | setBlock = CreateSetTime();
|
---|
379 | break;
|
---|
380 | // 現在日付
|
---|
381 | case 0x98:
|
---|
382 | setBlock = CreateSetDate();
|
---|
383 | break;
|
---|
384 | default:
|
---|
385 | setBlock = Document.CreateElement("block");
|
---|
386 | setBlock.SetAttribute("type", EcnlSaveReceivedPropertyBlock.type_name);
|
---|
387 | break;
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (setBlock != null) {
|
---|
391 | var statement = Document.CreateElement("statement");
|
---|
392 | statement.SetAttribute("name", "DEFAULT_SET");
|
---|
393 | block.AppendChild(statement);
|
---|
394 |
|
---|
395 | statement.AppendChild(setBlock);
|
---|
396 | }
|
---|
397 | }
|
---|
398 | else {
|
---|
399 | var mutation = Document.CreateElement("mutation");
|
---|
400 | mutation.SetAttribute("property_code", pi.propertyCode.ToString("X2"));
|
---|
401 | mutation.SetAttribute("identifier", identifier);
|
---|
402 | mutation.SetAttribute("description", pi.description);
|
---|
403 | mutation.SetAttribute("property_size", pi.size.ToString());
|
---|
404 | mutation.SetAttribute("default", "0");
|
---|
405 | mutation.SetAttribute("user_getter", "1");
|
---|
406 | block.AppendChild(mutation);
|
---|
407 |
|
---|
408 | int i = 0;
|
---|
409 | foreach (var v in valueRange.Values) {
|
---|
410 | var branch = Document.CreateElement("case");
|
---|
411 | branch.SetAttribute("value", v.Val.ToString());
|
---|
412 | branch.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
413 | mutation.AppendChild(branch);
|
---|
414 |
|
---|
415 | field = Document.CreateElement("field");
|
---|
416 | field.SetAttribute("name", "CASE_DESCRIPTION" + i);
|
---|
417 | field.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
418 | block.AppendChild(field);
|
---|
419 |
|
---|
420 | field = Document.CreateElement("field");
|
---|
421 | field.SetAttribute("name", "CASE_VALUE" + i);
|
---|
422 | field.AppendChild(Document.CreateTextNode(v.Val.ToString()));
|
---|
423 | block.AppendChild(field);
|
---|
424 |
|
---|
425 | var statement = Document.CreateElement("statement");
|
---|
426 | statement.SetAttribute("name", "SET" + i);
|
---|
427 | block.AppendChild(statement);
|
---|
428 |
|
---|
429 | var setBlock = Document.CreateElement("shadow");
|
---|
430 | setBlock.SetAttribute("type", EcnlSaveReceivedPropertyBlock.type_name);
|
---|
431 | statement.AppendChild(setBlock);
|
---|
432 |
|
---|
433 | i++;
|
---|
434 | }
|
---|
435 |
|
---|
436 | foreach (var v in valueRange.Ranges) {
|
---|
437 | var branch = Document.CreateElement("case");
|
---|
438 | branch.SetAttribute("minimum", v.Min.ToString());
|
---|
439 | branch.SetAttribute("maximum", v.Max.ToString());
|
---|
440 | branch.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
441 | mutation.AppendChild(branch);
|
---|
442 |
|
---|
443 | field = Document.CreateElement("field");
|
---|
444 | field.SetAttribute("name", "CASE_DESCRIPTION" + i);
|
---|
445 | field.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
446 | block.AppendChild(field);
|
---|
447 |
|
---|
448 | field = Document.CreateElement("field");
|
---|
449 | field.SetAttribute("name", "CASE_MIN" + i);
|
---|
450 | field.AppendChild(Document.CreateTextNode(v.Min.ToString()));
|
---|
451 | block.AppendChild(field);
|
---|
452 |
|
---|
453 | field = Document.CreateElement("field");
|
---|
454 | field.SetAttribute("name", "CASE_MAX" + i);
|
---|
455 | field.AppendChild(Document.CreateTextNode(v.Max.ToString()));
|
---|
456 | block.AppendChild(field);
|
---|
457 |
|
---|
458 | var statement = Document.CreateElement("statement");
|
---|
459 | statement.SetAttribute("name", "SET" + i);
|
---|
460 | block.AppendChild(statement);
|
---|
461 |
|
---|
462 | var setBlock = Document.CreateElement("shadow");
|
---|
463 | setBlock.SetAttribute("type", EcnlSaveReceivedPropertyBlock.type_name);
|
---|
464 | statement.AppendChild(setBlock);
|
---|
465 |
|
---|
466 | i++;
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | {
|
---|
471 | var statement = Document.CreateElement("statement");
|
---|
472 | statement.SetAttribute("name", "GET");
|
---|
473 | block.AppendChild(statement);
|
---|
474 |
|
---|
475 | Element ifBlock = null;
|
---|
476 | if (varlen) {
|
---|
477 | ifBlock = CreateSizeCheckBlocks();
|
---|
478 | statement.AppendChild(ifBlock);
|
---|
479 | }
|
---|
480 |
|
---|
481 | Element getBlock = null;
|
---|
482 | switch (pi.propertyCode) {
|
---|
483 | // 現在時刻
|
---|
484 | case 0x97:
|
---|
485 | getBlock = CreateGetTime(identifier);
|
---|
486 | break;
|
---|
487 | // 現在日付
|
---|
488 | case 0x98:
|
---|
489 | getBlock = CreateGetDate(identifier);
|
---|
490 | break;
|
---|
491 | default:
|
---|
492 | break;
|
---|
493 | }
|
---|
494 |
|
---|
495 | if (getBlock != null) {
|
---|
496 | if (ifBlock != null) {
|
---|
497 | var next = Document.CreateElement("next");
|
---|
498 | next.AppendChild(getBlock);
|
---|
499 |
|
---|
500 | ifBlock.AppendChild(next);
|
---|
501 | }
|
---|
502 | else {
|
---|
503 | statement.AppendChild(getBlock);
|
---|
504 | }
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | {
|
---|
509 | var value = Document.CreateElement("value");
|
---|
510 | value.SetAttribute("name", "GET_RET");
|
---|
511 | block.AppendChild(value);
|
---|
512 |
|
---|
513 | Element subblock = null;
|
---|
514 | switch (pi.propertyCode) {
|
---|
515 | // 現在時刻
|
---|
516 | case 0x97:
|
---|
517 | subblock = CreateGetRetTime(identifier);
|
---|
518 | break;
|
---|
519 | // 現在日付
|
---|
520 | case 0x98:
|
---|
521 | subblock = CreateGetRetDate(identifier);
|
---|
522 | break;
|
---|
523 | default:
|
---|
524 | subblock = Document.CreateElement("block");
|
---|
525 | subblock.SetAttribute("type", EcnlGetSavedPropertyBlock.type_name);
|
---|
526 | break;
|
---|
527 | }
|
---|
528 |
|
---|
529 | if (subblock != null) {
|
---|
530 | value.AppendChild(subblock);
|
---|
531 | }
|
---|
532 | }
|
---|
533 | }
|
---|
534 |
|
---|
535 | return xmlList;
|
---|
536 | }
|
---|
537 |
|
---|
538 | private Element CreateSetDate()
|
---|
539 | {
|
---|
540 | var localvar = "date";
|
---|
541 | var setBlock = CreateGetDateTimeBlock(localvar);
|
---|
542 |
|
---|
543 | var next = Document.CreateElement("next");
|
---|
544 | setBlock.AppendChild(next);
|
---|
545 |
|
---|
546 | var rtcBlock = CreateSetDateTimeItemBlock(localvar, "0", "SHORT", 0);
|
---|
547 | next.AppendChild(rtcBlock);
|
---|
548 |
|
---|
549 | next = Document.CreateElement("next");
|
---|
550 | rtcBlock.AppendChild(next);
|
---|
551 |
|
---|
552 | rtcBlock = CreateSetDateTimeItemBlock(localvar, "1", "BYTE", 2);
|
---|
553 | next.AppendChild(rtcBlock);
|
---|
554 |
|
---|
555 | next = Document.CreateElement("next");
|
---|
556 | rtcBlock.AppendChild(next);
|
---|
557 |
|
---|
558 | rtcBlock = CreateSetDateTimeItemBlock(localvar, "2", "BYTE", 3);
|
---|
559 | next.AppendChild(rtcBlock);
|
---|
560 |
|
---|
561 | next = Document.CreateElement("next");
|
---|
562 | rtcBlock.AppendChild(next);
|
---|
563 |
|
---|
564 | var callBlock = CreateSetDateTimeBlock(localvar);
|
---|
565 | next.AppendChild(callBlock);
|
---|
566 |
|
---|
567 | return setBlock;
|
---|
568 | }
|
---|
569 |
|
---|
570 | private Element CreateGetDate(string name)
|
---|
571 | {
|
---|
572 | return CreateGetDateTimeBlock(name);
|
---|
573 | }
|
---|
574 |
|
---|
575 | private Element CreateGetRetDate(string name)
|
---|
576 | {
|
---|
577 | var subBlock = Document.CreateElement("block");
|
---|
578 | subBlock.SetAttribute("type", DataJoinBlock.type_name);
|
---|
579 |
|
---|
580 | var mutation = Document.CreateElement("mutation");
|
---|
581 | mutation.SetAttribute("items", "3");
|
---|
582 | subBlock.AppendChild(mutation);
|
---|
583 |
|
---|
584 | var value = Document.CreateElement("value");
|
---|
585 | value.SetAttribute("name", "ADD0");
|
---|
586 | subBlock.AppendChild(value);
|
---|
587 |
|
---|
588 | var rtcBlock = CreateGetDateTimeBlock(name, "0");
|
---|
589 | value.AppendChild(rtcBlock);
|
---|
590 |
|
---|
591 | value = Document.CreateElement("value");
|
---|
592 | value.SetAttribute("name", "ADD1");
|
---|
593 | subBlock.AppendChild(value);
|
---|
594 |
|
---|
595 | rtcBlock = CreateGetDateTimeBlock(name, "1");
|
---|
596 | value.AppendChild(rtcBlock);
|
---|
597 |
|
---|
598 | value = Document.CreateElement("value");
|
---|
599 | value.SetAttribute("name", "ADD2");
|
---|
600 | subBlock.AppendChild(value);
|
---|
601 |
|
---|
602 | rtcBlock = CreateGetDateTimeBlock(name, "2");
|
---|
603 | value.AppendChild(rtcBlock);
|
---|
604 |
|
---|
605 | return subBlock;
|
---|
606 | }
|
---|
607 |
|
---|
608 | private Element CreateSetTime()
|
---|
609 | {
|
---|
610 | var localvar = "time";
|
---|
611 | var setBlock = CreateGetDateTimeBlock(localvar);
|
---|
612 |
|
---|
613 | var next = Document.CreateElement("next");
|
---|
614 | setBlock.AppendChild(next);
|
---|
615 |
|
---|
616 | var rtcBlock = CreateSetDateTimeItemBlock(localvar, "3", "BYTE", 0);
|
---|
617 | next.AppendChild(rtcBlock);
|
---|
618 |
|
---|
619 | next = Document.CreateElement("next");
|
---|
620 | rtcBlock.AppendChild(next);
|
---|
621 |
|
---|
622 | rtcBlock = CreateSetDateTimeItemBlock(localvar, "4", "BYTE", 1);
|
---|
623 | next.AppendChild(rtcBlock);
|
---|
624 |
|
---|
625 | next = Document.CreateElement("next");
|
---|
626 | rtcBlock.AppendChild(next);
|
---|
627 |
|
---|
628 | var callBlock = CreateSetDateTimeBlock(localvar);
|
---|
629 | next.AppendChild(callBlock);
|
---|
630 |
|
---|
631 | return setBlock;
|
---|
632 | }
|
---|
633 |
|
---|
634 | private Element CreateGetTime(string name)
|
---|
635 | {
|
---|
636 | return CreateGetDateTimeBlock(name);
|
---|
637 | }
|
---|
638 |
|
---|
639 | private Element CreateGetRetTime(string name)
|
---|
640 | {
|
---|
641 | var subBlock = Document.CreateElement("block");
|
---|
642 | subBlock.SetAttribute("type", DataJoinBlock.type_name);
|
---|
643 |
|
---|
644 | var mutation = Document.CreateElement("mutation");
|
---|
645 | mutation.SetAttribute("items", "2");
|
---|
646 | subBlock.AppendChild(mutation);
|
---|
647 |
|
---|
648 | var value = Document.CreateElement("value");
|
---|
649 | value.SetAttribute("name", "ADD0");
|
---|
650 | subBlock.AppendChild(value);
|
---|
651 |
|
---|
652 | var rtcBlock = CreateGetDateTimeBlock(name, "3");
|
---|
653 | value.AppendChild(rtcBlock);
|
---|
654 |
|
---|
655 | value = Document.CreateElement("value");
|
---|
656 | value.SetAttribute("name", "ADD1");
|
---|
657 | subBlock.AppendChild(value);
|
---|
658 |
|
---|
659 | rtcBlock = CreateGetDateTimeBlock(name, "4");
|
---|
660 | value.AppendChild(rtcBlock);
|
---|
661 |
|
---|
662 | return subBlock;
|
---|
663 | }
|
---|
664 |
|
---|
665 | private Element CreateGetDateTimeBlock(string name, string item)
|
---|
666 | {
|
---|
667 | var rtcBlock = Document.CreateElement("block");
|
---|
668 | rtcBlock.SetAttribute("type", RtcDateTimeItemBlock.type_name);
|
---|
669 |
|
---|
670 | var field = Document.CreateElement("field");
|
---|
671 | field.SetAttribute("name", "ARRAY");
|
---|
672 | field.AppendChild(Document.CreateTextNode(name));
|
---|
673 | rtcBlock.AppendChild(field);
|
---|
674 |
|
---|
675 | field = Document.CreateElement("field");
|
---|
676 | field.SetAttribute("name", "ITEM");
|
---|
677 | field.AppendChild(Document.CreateTextNode(item));
|
---|
678 | rtcBlock.AppendChild(field);
|
---|
679 |
|
---|
680 | return rtcBlock;
|
---|
681 | }
|
---|
682 |
|
---|
683 | private Element CreateGetDateTimeBlock(string name)
|
---|
684 | {
|
---|
685 | var block = Document.CreateElement("block");
|
---|
686 | block.SetAttribute("type", VariablesSetBlock.type_name);
|
---|
687 |
|
---|
688 | var field = Document.CreateElement("field");
|
---|
689 | field.SetAttribute("name", "VAR");
|
---|
690 | field.AppendChild(Document.CreateTextNode(name));
|
---|
691 | block.AppendChild(field);
|
---|
692 |
|
---|
693 | var value = Document.CreateElement("value");
|
---|
694 | value.SetAttribute("name", "VALUE");
|
---|
695 | block.AppendChild(value);
|
---|
696 |
|
---|
697 | var rtcBlock = Document.CreateElement("block");
|
---|
698 | rtcBlock.SetAttribute("type", RtcGetTimeBlock.type_name);
|
---|
699 | value.AppendChild(rtcBlock);
|
---|
700 |
|
---|
701 | return block;
|
---|
702 | }
|
---|
703 |
|
---|
704 | private Element CreateSetDateTimeBlock(string localvar)
|
---|
705 | {
|
---|
706 | var callBlock = Document.CreateElement("block");
|
---|
707 | callBlock.SetAttribute("type", CallBlock.type_name);
|
---|
708 |
|
---|
709 | var value = Document.CreateElement("value");
|
---|
710 | value.SetAttribute("name", "RET");
|
---|
711 | callBlock.AppendChild(value);
|
---|
712 |
|
---|
713 | var rtcBlock = Document.CreateElement("block");
|
---|
714 | rtcBlock.SetAttribute("type", RtcSettimeBlock.type_name);
|
---|
715 | value.AppendChild(rtcBlock);
|
---|
716 |
|
---|
717 | value = Document.CreateElement("value");
|
---|
718 | value.SetAttribute("name", "DATE");
|
---|
719 | rtcBlock.AppendChild(value);
|
---|
720 |
|
---|
721 | var vgetBlock = Document.CreateElement("block");
|
---|
722 | vgetBlock.SetAttribute("type", VariablesGetBlock.type_name);
|
---|
723 | value.AppendChild(vgetBlock);
|
---|
724 |
|
---|
725 | var field = Document.CreateElement("field");
|
---|
726 | field.SetAttribute("name", "VAR");
|
---|
727 | field.AppendChild(Document.CreateTextNode(localvar));
|
---|
728 | vgetBlock.AppendChild(field);
|
---|
729 |
|
---|
730 | return callBlock;
|
---|
731 | }
|
---|
732 |
|
---|
733 | private Element CreateSetDateTimeItemBlock(string localvar, string item, string width, int pos)
|
---|
734 | {
|
---|
735 | var rtcBlock = Document.CreateElement("block");
|
---|
736 | rtcBlock.SetAttribute("type", RtcSetDateTimeItemBlock.type_name);
|
---|
737 |
|
---|
738 | var field = Document.CreateElement("field");
|
---|
739 | field.SetAttribute("name", "ARRAY");
|
---|
740 | field.AppendChild(Document.CreateTextNode(localvar));
|
---|
741 | rtcBlock.AppendChild(field);
|
---|
742 |
|
---|
743 | field = Document.CreateElement("field");
|
---|
744 | field.SetAttribute("name", "ITEM");
|
---|
745 | field.AppendChild(Document.CreateTextNode(item));
|
---|
746 | rtcBlock.AppendChild(field);
|
---|
747 |
|
---|
748 | var value = Document.CreateElement("value");
|
---|
749 | value.SetAttribute("name", "VALUE");
|
---|
750 | rtcBlock.AppendChild(value);
|
---|
751 |
|
---|
752 | var dataBlock = CreateReceivedData(width, pos);
|
---|
753 | value.AppendChild(dataBlock);
|
---|
754 |
|
---|
755 | return rtcBlock;
|
---|
756 | }
|
---|
757 |
|
---|
758 | private Element CreateAnnoCheck()
|
---|
759 | {
|
---|
760 | var annoBlock = Document.CreateElement("block");
|
---|
761 | annoBlock.SetAttribute("type", EcnlSetAnnounceRequestBlock.type_name);
|
---|
762 |
|
---|
763 | var value = Document.CreateElement("value");
|
---|
764 | value.SetAttribute("name", "DATA");
|
---|
765 | annoBlock.AppendChild(value);
|
---|
766 |
|
---|
767 | var subblock = Document.CreateElement("block");
|
---|
768 | subblock.SetAttribute("type", EcnlGetSavedPropertyBlock.type_name);
|
---|
769 | value.AppendChild(subblock);
|
---|
770 | return annoBlock;
|
---|
771 | }
|
---|
772 |
|
---|
773 | private Element CreateSizeCheckBlocks()
|
---|
774 | {
|
---|
775 | Element field;
|
---|
776 | var ifBlock = Document.CreateElement("block");
|
---|
777 | ifBlock.SetAttribute("type", ControlsIfBlock.type_name);
|
---|
778 |
|
---|
779 | var value = Document.CreateElement("value");
|
---|
780 | value.SetAttribute("name", "IF0");
|
---|
781 | ifBlock.AppendChild(value);
|
---|
782 |
|
---|
783 | var compBlock = Document.CreateElement("block");
|
---|
784 | compBlock.SetAttribute("type", LogicCompareBlock.type_name);
|
---|
785 | value.AppendChild(compBlock);
|
---|
786 |
|
---|
787 | field = Document.CreateElement("field");
|
---|
788 | field.SetAttribute("name", "OP");
|
---|
789 | field.AppendChild(Document.CreateTextNode("NEQ"));
|
---|
790 | compBlock.AppendChild(field);
|
---|
791 |
|
---|
792 | value = Document.CreateElement("value");
|
---|
793 | value.SetAttribute("name", "A");
|
---|
794 | compBlock.AppendChild(value);
|
---|
795 |
|
---|
796 | var subblock = Document.CreateElement("block");
|
---|
797 | subblock.SetAttribute("type", EcnlReceivedDataSizeBlock.type_name);
|
---|
798 | value.AppendChild(subblock);
|
---|
799 |
|
---|
800 | value = Document.CreateElement("value");
|
---|
801 | value.SetAttribute("name", "B");
|
---|
802 | compBlock.AppendChild(value);
|
---|
803 |
|
---|
804 | subblock = Document.CreateElement("block");
|
---|
805 | subblock.SetAttribute("type", EcnlGetPropertyInfoBlock.type_name);
|
---|
806 | value.AppendChild(subblock);
|
---|
807 |
|
---|
808 | field = Document.CreateElement("field");
|
---|
809 | field.SetAttribute("name", "MEMBER");
|
---|
810 | field.AppendChild(Document.CreateTextNode("sz"));
|
---|
811 | subblock.AppendChild(field);
|
---|
812 |
|
---|
813 | var doStatement = Document.CreateElement("statement");
|
---|
814 | doStatement.SetAttribute("name", "DO0");
|
---|
815 | ifBlock.AppendChild(doStatement);
|
---|
816 |
|
---|
817 | subblock = Document.CreateElement("block");
|
---|
818 | subblock.SetAttribute("type", EcnlNoOpBlock.type_name);
|
---|
819 | doStatement.AppendChild(subblock);
|
---|
820 |
|
---|
821 | return ifBlock;
|
---|
822 | }
|
---|
823 |
|
---|
824 | private Element CreateSetStatement(ValueRange valueRange)
|
---|
825 | {
|
---|
826 | Element field;
|
---|
827 |
|
---|
828 | var block = Document.CreateElement("block");
|
---|
829 | block.SetAttribute("type", SwitchCaseNumberBlock.type_name);
|
---|
830 |
|
---|
831 | var mutation = Document.CreateElement("mutation");
|
---|
832 | mutation.SetAttribute("default", "1");
|
---|
833 | block.AppendChild(mutation);
|
---|
834 |
|
---|
835 | int i = 0;
|
---|
836 | foreach (var v in valueRange.Values) {
|
---|
837 | var branch = Document.CreateElement("case");
|
---|
838 | branch.SetAttribute("value", v.Val.ToString());
|
---|
839 | branch.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
840 | mutation.AppendChild(branch);
|
---|
841 |
|
---|
842 | field = Document.CreateElement("field");
|
---|
843 | field.SetAttribute("name", "DESCRIPTION" + i);
|
---|
844 | field.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
845 | block.AppendChild(field);
|
---|
846 |
|
---|
847 | field = Document.CreateElement("field");
|
---|
848 | field.SetAttribute("name", "CONST" + i);
|
---|
849 | field.AppendChild(Document.CreateTextNode(v.Val.ToString()));
|
---|
850 | block.AppendChild(field);
|
---|
851 | i++;
|
---|
852 | }
|
---|
853 |
|
---|
854 | foreach (var v in valueRange.Ranges) {
|
---|
855 | var branch = Document.CreateElement("case");
|
---|
856 | branch.SetAttribute("minimum", v.Min.ToString());
|
---|
857 | branch.SetAttribute("maximum", v.Max.ToString());
|
---|
858 | branch.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
859 | mutation.AppendChild(branch);
|
---|
860 |
|
---|
861 | field = Document.CreateElement("field");
|
---|
862 | field.SetAttribute("name", "DESCRIPTION" + i);
|
---|
863 | field.AppendChild(Document.CreateTextNode(v.Disp.ToString()));
|
---|
864 | block.AppendChild(field);
|
---|
865 |
|
---|
866 | field = Document.CreateElement("field");
|
---|
867 | field.SetAttribute("name", "RANGE_MIN" + i);
|
---|
868 | field.AppendChild(Document.CreateTextNode(v.Min.ToString()));
|
---|
869 | block.AppendChild(field);
|
---|
870 |
|
---|
871 | field = Document.CreateElement("field");
|
---|
872 | field.SetAttribute("name", "RANGE_MAX" + i);
|
---|
873 | field.AppendChild(Document.CreateTextNode(v.Max.ToString()));
|
---|
874 | block.AppendChild(field);
|
---|
875 | i++;
|
---|
876 | }
|
---|
877 |
|
---|
878 | return block;
|
---|
879 | }
|
---|
880 |
|
---|
881 | private Element CreateReceivedData(string width, int pos)
|
---|
882 | {
|
---|
883 | var block = Document.CreateElement("block");
|
---|
884 | block.SetAttribute("type", EcnlDataToNumberBlock.type_name);
|
---|
885 |
|
---|
886 | var field = Document.CreateElement("field");
|
---|
887 | field.SetAttribute("name", "WIDTH");
|
---|
888 | field.AppendChild(Document.CreateTextNode(width));
|
---|
889 | block.AppendChild(field);
|
---|
890 |
|
---|
891 | var value = Document.CreateElement("value");
|
---|
892 | value.SetAttribute("name", "POSITION");
|
---|
893 | block.AppendChild(value);
|
---|
894 |
|
---|
895 | var subBlock = Document.CreateElement("shadow");
|
---|
896 | subBlock.SetAttribute("type", MathNumberBlock.type_name);
|
---|
897 | value.AppendChild(subBlock);
|
---|
898 |
|
---|
899 | field = Document.CreateElement("field");
|
---|
900 | field.SetAttribute("name", "NUM");
|
---|
901 | field.AppendChild(Document.CreateTextNode(pos.ToString()));
|
---|
902 | subBlock.AppendChild(field);
|
---|
903 |
|
---|
904 | return block;
|
---|
905 | }
|
---|
906 |
|
---|
907 | private Element RengeCheack(string width, int pos, long min, long max)
|
---|
908 | {
|
---|
909 | var block2 = Document.CreateElement("block");
|
---|
910 | block2.SetAttribute("type", LogicOperationBlock.type_name);
|
---|
911 |
|
---|
912 | var field = Document.CreateElement("field");
|
---|
913 | field.SetAttribute("name", "OP");
|
---|
914 | field.AppendChild(Document.CreateTextNode("AND"));
|
---|
915 | block2.AppendChild(field);
|
---|
916 |
|
---|
917 | var value = Document.CreateElement("value");
|
---|
918 | value.SetAttribute("name", "A");
|
---|
919 | block2.AppendChild(value);
|
---|
920 |
|
---|
921 | var a = CompareNum(width, pos, "GTE", min);
|
---|
922 | value.AppendChild(a);
|
---|
923 |
|
---|
924 | value = Document.CreateElement("value");
|
---|
925 | value.SetAttribute("name", "B");
|
---|
926 | block2.AppendChild(value);
|
---|
927 |
|
---|
928 | var b = CompareNum(width, pos, "LTE", max);
|
---|
929 | value.AppendChild(b);
|
---|
930 |
|
---|
931 | return block2;
|
---|
932 | }
|
---|
933 |
|
---|
934 | private Element CompareNum(string width, int pos, string OP, long num)
|
---|
935 | {
|
---|
936 | var block3 = Document.CreateElement("block");
|
---|
937 | block3.SetAttribute("type", LogicCompareBlock.type_name);
|
---|
938 |
|
---|
939 | var field = Document.CreateElement("field");
|
---|
940 | field.SetAttribute("name", "OP");
|
---|
941 | field.AppendChild(Document.CreateTextNode(OP));
|
---|
942 | block3.AppendChild(field);
|
---|
943 |
|
---|
944 | var value = Document.CreateElement("value");
|
---|
945 | value.SetAttribute("name", "A");
|
---|
946 | block3.AppendChild(value);
|
---|
947 |
|
---|
948 | var block4 = CreateReceivedData(width, pos);
|
---|
949 | value.AppendChild(block4);
|
---|
950 |
|
---|
951 | value = Document.CreateElement("value");
|
---|
952 | value.SetAttribute("name", "B");
|
---|
953 | block3.AppendChild(value);
|
---|
954 |
|
---|
955 | block4 = Document.CreateElement("block");
|
---|
956 | block4.SetAttribute("type", MathNumberBlock.type_name);
|
---|
957 | value.AppendChild(block4);
|
---|
958 |
|
---|
959 | field = Document.CreateElement("field");
|
---|
960 | field.SetAttribute("name", "NUM");
|
---|
961 | field.AppendChild(Document.CreateTextNode(num.ToString()));
|
---|
962 | block4.AppendChild(field);
|
---|
963 |
|
---|
964 | return block3;
|
---|
965 | }
|
---|
966 |
|
---|
967 | public void OpenModifyView(Action<bool> callback)
|
---|
968 | {
|
---|
969 | if (this.callback != null)
|
---|
970 | return;
|
---|
971 | this.callback = callback;
|
---|
972 |
|
---|
973 | Views.EObjectModalView.SetEObject(eobject, GetImageUrl());
|
---|
974 | Views.EObjectModalView.Closed += EObjectModalView_Closed;
|
---|
975 | Views.EObjectModalView.Render();
|
---|
976 | }
|
---|
977 |
|
---|
978 | private void EObjectModalView_Closed(EObjectModalView view, bool ok)
|
---|
979 | {
|
---|
980 | view.Closed -= EObjectModalView_Closed;
|
---|
981 |
|
---|
982 | if (ok) {
|
---|
983 | View.Identifier = eobject.identifier;
|
---|
984 | View.ReloadToolbox(this);
|
---|
985 | UpdateInitialBlock();
|
---|
986 | }
|
---|
987 |
|
---|
988 | callback?.Invoke(ok);
|
---|
989 | callback = null;
|
---|
990 | }
|
---|
991 |
|
---|
992 | public string Template(string template)
|
---|
993 | {
|
---|
994 | template = template.Replace("%identifier%", eobject.identifier);
|
---|
995 | template = template.Replace("%attribute%", "EOBJ: " + eobject.type.classGroup.classGroupCode.ToString("X2") + eobject.type.classCode.ToString("X2") + eobject.instanceCode.ToString("X2")
|
---|
996 | + "<br>区分: " + eobject.attribute);
|
---|
997 | template = template.Replace("%img%", GetImageUrl());
|
---|
998 | return template;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | internal void OnBlockCreated(object sender, Create cre)
|
---|
1002 | {
|
---|
1003 | var block = workspace.getBlockById(cre.blockId);
|
---|
1004 |
|
---|
1005 | if (block.type == ENodeInitializeBlock.type_name) {
|
---|
1006 | var nodeBlock = (ENodeInitializeBlock)block;
|
---|
1007 | nodeBlock.OnCreate(this, cre);
|
---|
1008 | }
|
---|
1009 | else if (block.type == EObjectInitializeBlock.type_name) {
|
---|
1010 | var objectBlock = (EObjectInitializeBlock)block;
|
---|
1011 | objectBlock.OnCreate(this, cre);
|
---|
1012 | }
|
---|
1013 | else if (block.type == EPropertyVarLenBlock.type_name) {
|
---|
1014 | var propertyBlock = (EPropertyVarLenBlock)block;
|
---|
1015 | propertyBlock.OnCreate(this, cre);
|
---|
1016 | }
|
---|
1017 | else if (block.type == EPropertyFixLenBlock.type_name) {
|
---|
1018 | var propertyBlock = (EPropertyFixLenBlock)block;
|
---|
1019 | propertyBlock.OnCreate(this, cre);
|
---|
1020 | }
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | internal void OnBlockDeleted(object sender, Delete del)
|
---|
1024 | {
|
---|
1025 | var block = workspace.getBlockById(del.blockId);
|
---|
1026 |
|
---|
1027 | if (block != null) {
|
---|
1028 | if (block.type == ENodeInitializeBlock.type_name) {
|
---|
1029 | var nodeBlock = (ENodeInitializeBlock)block;
|
---|
1030 | nodeBlock.OnDelete(this, del);
|
---|
1031 | }
|
---|
1032 | else if (block.type == EObjectInitializeBlock.type_name) {
|
---|
1033 | var objectBlock = (EObjectInitializeBlock)block;
|
---|
1034 | objectBlock.OnDelete(this, del);
|
---|
1035 | }
|
---|
1036 | else if (block.type == EPropertyVarLenBlock.type_name) {
|
---|
1037 | var propertyBlock = (EPropertyVarLenBlock)block;
|
---|
1038 | propertyBlock.OnDelete(this, del);
|
---|
1039 | }
|
---|
1040 | else if (block.type == EPropertyFixLenBlock.type_name) {
|
---|
1041 | var propertyBlock = (EPropertyFixLenBlock)block;
|
---|
1042 | propertyBlock.OnDelete(this, del);
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | internal void OnBlockChanged(object sender, Change chg)
|
---|
1048 | {
|
---|
1049 | var block = workspace.getBlockById(chg.blockId);
|
---|
1050 |
|
---|
1051 | if (block.type == ENodeInitializeBlock.type_name) {
|
---|
1052 | var nodeBlock = (ENodeInitializeBlock)block;
|
---|
1053 | nodeBlock.OnChange(this, chg);
|
---|
1054 | }
|
---|
1055 | else if (block.type == EObjectInitializeBlock.type_name) {
|
---|
1056 | var objectBlock = (EObjectInitializeBlock)block;
|
---|
1057 | objectBlock.OnChange(this, chg);
|
---|
1058 | }
|
---|
1059 | else if (block.type == EPropertyVarLenBlock.type_name) {
|
---|
1060 | var propertyBlock = (EPropertyVarLenBlock)block;
|
---|
1061 | propertyBlock.OnChange(this, chg);
|
---|
1062 | }
|
---|
1063 | else if (block.type == EPropertyFixLenBlock.type_name) {
|
---|
1064 | var propertyBlock = (EPropertyFixLenBlock)block;
|
---|
1065 | propertyBlock.OnChange(this, chg);
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | internal void OnBlockMoveed(object sender, Move mov)
|
---|
1070 | {
|
---|
1071 | var block = workspace.getBlockById(mov.blockId);
|
---|
1072 |
|
---|
1073 | if (block != null) {
|
---|
1074 | if (block.type == ENodeInitializeBlock.type_name) {
|
---|
1075 | var nodeBlock = (ENodeInitializeBlock)block;
|
---|
1076 | nodeBlock.OnMove(this, mov);
|
---|
1077 | }
|
---|
1078 | else if (block.type == EObjectInitializeBlock.type_name) {
|
---|
1079 | var objectBlock = (EObjectInitializeBlock)block;
|
---|
1080 | objectBlock.OnMove(this, mov);
|
---|
1081 | }
|
---|
1082 | else if (block.type == EPropertyVarLenBlock.type_name) {
|
---|
1083 | var propertyBlock = (EPropertyVarLenBlock)block;
|
---|
1084 | propertyBlock.OnMove(this, mov);
|
---|
1085 | }
|
---|
1086 | else if (block.type == EPropertyFixLenBlock.type_name) {
|
---|
1087 | var propertyBlock = (EPropertyFixLenBlock)block;
|
---|
1088 | propertyBlock.OnMove(this, mov);
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | internal class ENodeWorkspace : EObjectWorkspace
|
---|
1095 | {
|
---|
1096 | public JsonNodeInfo enode { get { return (JsonNodeInfo)eobject; } }
|
---|
1097 |
|
---|
1098 | public ENodeWorkspace(BlocklyView view, JsonNodeInfo enode)
|
---|
1099 | : base(view, enode)
|
---|
1100 | {
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | public override string GetImageUrl()
|
---|
1104 | {
|
---|
1105 | return "img/no_image.png";
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | public override bool IsPreset()
|
---|
1109 | {
|
---|
1110 | return true;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | public override string ToCode(string filename)
|
---|
1114 | {
|
---|
1115 | if (eobject == null)
|
---|
1116 | return "";
|
---|
1117 |
|
---|
1118 | _RubyCode = new Ruby(filename);
|
---|
1119 | _RubyCode.init(Workspace);
|
---|
1120 | var result = _RubyCode.defineENode((JsonNodeInfo)eobject, Workspace);
|
---|
1121 | View.Changed = false;
|
---|
1122 | return result;
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 | }
|
---|