Quantum Fog  0.9.3
NODE.h
1 #pragma once
2 
3 #include "QFog_constants.h"
4 
5 
6 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
7 
8  #include "C_PORT_RELATED.h"
9  #include "C_COLORS.h"
10  class C_MAIN_VIEW;
11  #include "C_ND_EFIELD.h"
12  #include "MY_FSTREAMS.h"
13  #include "C_AMP_GEN.h"
14 #endif //_mac_gui_app \\............................................//
15 
16 
17 
18 
19 #include "STRINGY.h"
20 #include "VECTOR.h"
21 #include "TRANS_MAT.h"
22 #include "STRETCH_OR_FOLD.h"
23 //#include "L_LIST.h"
24 #include "DICTIONARY.h"
25 #include "SET.h"
26 #include "UI_MAP.h"
27 //******************************************
29 {
30 public:
31  USHORT its_num_of_comps;
32  CHAR its_min_char;
33  CHAR its_max_char;
34  BOOLEAN its_has_commas;
35 
37 };
38 
39 enum ND_CLASS_ID {
40 NO_NODE_id=0,
41 BEAM_SPL_id,
42 CUSTOM_ND_id,
43 DET_ND_id,
44 POL_ROTATOR_id,
45 POLARIZER_id,
46 QBIT_ROT_id,
47 SG_MAGNET_id
48 };//keep in mind that if you add a new id type
49 //to this list, and you don't add it to the end of the list,
50 //the values of successive ids in the list will change.
51 //******************************************
52 class NODE
53 {
54 protected:
55  STRINGY its_name;
56  USHORT its_degen;
57 
58  VECTOR<STRINGY> its_st_names; // st = state
59  DICTIONARY * its_st_name_dict_p;
60 
61  VECTOR<USHORT> its_in_nds; // nds = nodes, in = incoming
62  VECTOR<USHORT> its_in_nd_degens; // degens = numbers of states
63  STRETCH_OR_FOLD its_in_nd_sof;
64  TM_COL_NUM its_num_of_in_sts;
65 
66  VECTOR<USHORT> its_out_nds; // out = outgoing
67 
68  TRANS_MAT its_tm_amps; // amps = amplitudes
69 
70 
71  SET its_active_states;
72  SET its_tempo_active_states;
73 
74 
75  // The previous data members are the static info.
76  // The next data members are the dynamic info.
77  // By a dynamic(static) data member we mean one that
78  // changes repeatedly (does not change)
79  // when we call the function QB_NET::go_forward().
80 
81  // NOTE that cum_probs are not necessarily normalized,
82  // so they are not probabilities in the strict sense.
83  // One might call them quasi probabilities.
84 
85  USHORT its_dyn_st;
86  VECTOR<USHORT> its_dyn_in_st;
87  const DIR_NZ_ELE * its_dyn_dir_ele_p;
88 
89  VECTOR<COMPLEX> its_cum_amps; //cum = cummulative
90  VECTOR<DOUBLE> its_cum_probs;
91 
92 public:
93  NODE();
94  virtual ~NODE();
95 
96 
97  const STRINGY & get_name() const;
98  VOID set_name(const STRINGY & name);
99 
100  USHORT get_degen() const;
101  VOID set_degen(USHORT degen);
102 
103  const STRINGY & get_st_name(USHORT loc) const;
104  VOID set_st_name(USHORT row_num, const STRINGY & new_name);
105  virtual VOID set_st_names_to_default();
106  VOID set_st_names_to_monotone_seq(USHORT starting_point);
107  VOID set_st_names(const ST_NAMES_GENERATOR_DATA & v);
108  const DICTIONARY & get_dict() const;
109  VOID create_dict();
110  VOID kill_dict();
111 
112  TRANS_MAT & get_tm_amps();
113  VOID set_tm_amp(USHORT row, TM_COL_NUM col, const COMPLEX & z );
114  DOUBLE get_col_prob(TM_COL_NUM col);
115  VOID empty_trans_mat();
116 
117  TM_COL_NUM get_num_of_in_sts();
118  virtual VOID set_num_of_in_sts();
119  const VECTOR<USHORT> & get_in_nds() const;
120  const STRETCH_OR_FOLD & get_in_nd_sof() const;
121  USHORT get_num_of_in_nds() const;
122  virtual VOID add_in_nd(USHORT nd_id, USHORT nd_degen);
123  virtual VOID del_in_nd(USHORT nd_id);
124  const VECTOR<USHORT> & get_in_nd_degens() const;
125  virtual VOID set_in_nd_degen(USHORT nd_id, USHORT new_degen);
126  virtual VOID renumber_in_nds(const UI_MAP & map);
127  virtual VOID reorder_in_nds(const UI_MAP & map, BOOLEAN touch_tm);
128  virtual VOID change_in_nd_to_compatible_one(USHORT old_nd, USHORT new_nd);
129 
130 
131  const VECTOR<USHORT> & get_out_nds() const;
132  VOID add_out_nd(USHORT nd_id);
133  VOID del_out_nd(USHORT nd_id);
134  VOID renumber_out_nds(const UI_MAP & map);
135 
136  VOID reorder_sts(const UI_MAP & map);
137  VOID change_tm_as_part_of_reordering_nd_sts_of_a_pa(USHORT pa_id, const UI_MAP & map);
138 
139 
140  const SET & get_active_states() const;
141  VOID set_active_states(const SET & act_sts);
142  VOID empty_act_st_set();
143  VOID fill_act_st_set();
144  USHORT get_num_of_active_states();
145  BOOLEAN is_active_state(USHORT state);
146  VOID activate_state(USHORT state);
147  VOID deactivate_state(USHORT state);
148  VOID preserve_act_st_set();
149  VOID restore_act_st_set();
150 
151  USHORT get_dyn_st() const;
152  VOID set_dyn_st(USHORT dyn_st);
153  VOID set_dyn_st_and_dir_ele_ptr(USHORT dyn_st);
154  VOID advance_dyn_dir_ele_ptr();
155  VOID move_dyn_dir_ele_ptr_to_first_col();
156  BOOLEAN has_dyn_in_st() const;
157  const VECTOR<USHORT> & get_dyn_in_st() const;
158  VOID reset_dyn_in_st();
159  const COMPLEX & get_dyn_amp() const;
160  DOUBLE get_cum_prob(USHORT state) const;
161  VOID normalize_cum_probs();
162  VOID set_cum_info_to_default();
163  VOID add_to_dyn_st_entry_of_cum_amps(const COMPLEX & net_amp);
164  VOID prepare_cum_info_for_next_ending();
165 
166 
167 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
168 
169 protected:
170  Point its_center;
171  BOOLEAN its_is_selected;
172  C_ND_EFIELD * its_efield_p;
173 
174  // Equals max_ushort if no caption and number of state if there is:
175  USHORT its_state_num_for_cap;
176  Rect its_state_cap_frame;
177  enum {default_sel_rad=16, default_mask_rad=16};
178 
179  C_AMP_GEN * its_amp_gen_p;
180 public:
181  NODE( const Point & center);
182  virtual const STRINGY get_class_str()=0;
183  virtual ND_CLASS_ID get_class_id()=0;
184 
185 
186  virtual VOID call_amp_gen(QB_NET * net_p, C_PI_WIND * pi_wind_p)=0;
187 
188  C_ND_EFIELD * get_efield_ptr() const;
189  VOID set_efield_ptr(C_ND_EFIELD * efield_p);
190 
191  const Point & get_center() const;
192  //override if different from default
193  virtual USHORT get_sel_rad() const;
194  virtual USHORT get_mask_rad() const;
195 
196  virtual C_CIRCLE get_docking_cir(USHORT sub_nd_id);
197  virtual BOOLEAN pt_is_in_greeting_cir_of_avail_s_port(const Point & pt, USHORT & sub_nd_id);
198  virtual BOOLEAN pt_is_in_greeting_cir_of_avail_d_port(const Point & pt, USHORT & sub_nd_id);
199  virtual VOID add_nd_to_port_glist(USHORT g_nd_id, USHORT sub_nd_id);//glist = guest list
200  virtual VOID remove_nd_from_all_port_glists(USHORT g_nd_id);
201  virtual VOID renumber_nds_of_port_glists(const UI_MAP & map);
202 
203  BOOLEAN is_selected() const;
204  virtual BOOLEAN pt_is_in_sel_cir(const Point & pt);
205  virtual C_CIRCLE get_selection_cir();
206  virtual Boolean select(C_MAIN_VIEW * mview_p);
207  virtual Boolean unselect(C_MAIN_VIEW * mview_p);
208  virtual VOID toggle_select(C_MAIN_VIEW * mview_p);
209 
210 
211  VOID draw_sel_handles_wkr();
212  virtual VOID draw_sel_handles();
213  virtual VOID undraw_sel_handles();
214 
215  VOID draw_state_cap();
216  VOID undraw_state_cap();
217  VOID set_state_num_for_cap(USHORT state);
218 
219  virtual const RGBColor & get_color() const;
220  virtual VOID set_color(const RGBColor & color);
221  virtual BOOLEAN has_color();
222 
223  virtual VOID draw();
224  VOID undraw(SInt16 radius);
225  virtual VOID undraw();
226 
227  virtual VOID move_by(const Point & delta);
228 
229  virtual VOID rotate();
230  virtual SInt16 get_icon_dir() const;
231  virtual VOID set_icon_dir(SInt16 icon_dir);
232  virtual BOOLEAN has_icon_dir();
233 
234  VOID write_net_stream(LStream & net_stream);
235  VOID read_net_stream(LStream & net_stream);
236 
237 #endif //_mac_gui_app \\............................................//
238 
239 };
240 #pragma mark -
241 
242 //******************************************
243 inline
244 const STRINGY & NODE::get_name() const
245 {
246  return its_name;
247 }
248 //******************************************
249 inline
250 VOID NODE::set_name(
251 const STRINGY & name) //in
252 {
253  its_name = name;
254 }
255 //******************************************
256 inline
257 USHORT NODE::get_degen() const
258 {
259  return its_degen;
260 }
261 //******************************************
262 inline
263 const STRINGY & NODE::get_st_name(
264 USHORT loc) //in
265 const
266 {
267  return its_st_names[loc];
268 }
269 //******************************************
270 inline
271 VOID NODE::set_st_name(
272 USHORT row_num, //in
273 const STRINGY & new_name) //in
274 {
275  its_st_names[row_num]=new_name;
276 }
277 //******************************************
278 inline
279 VOID NODE::set_st_names_to_default()
280 {
281 }
282 //******************************************
283 inline
284 const DICTIONARY & NODE::get_dict() const
285 {
286  return *its_st_name_dict_p;
287 }
288 //******************************************
289 inline
290 TRANS_MAT & NODE::get_tm_amps()
291 {
292  return its_tm_amps;
293 }
294 //******************************************
295 inline
296 VOID NODE::set_tm_amp(
297 USHORT row, //in
298 TM_COL_NUM col, //in
299 const COMPLEX & z ) //in
300 {
301  its_tm_amps.set_ele(row, col, z);
302 }
303 //******************************************
304 inline
305 DOUBLE NODE::get_col_prob(
306 TM_COL_NUM col) //in
307 {
308  return its_tm_amps.get_col_prob(col);
309 }
310 //******************************************
311 inline
312 VOID NODE::empty_trans_mat()
313 {
314  its_tm_amps.set_to_zero_mat(its_degen, its_num_of_in_sts);
315 }
316 //******************************************
317 inline
318 TM_COL_NUM NODE::get_num_of_in_sts()
319 {
320  return its_num_of_in_sts;
321 }
322 //******************************************
323 inline
324 const VECTOR<USHORT> & NODE::get_in_nds() const
325 {
326  return its_in_nds;
327 }
328 //******************************************
329 inline
330 const STRETCH_OR_FOLD & NODE::get_in_nd_sof() const
331 {
332  return its_in_nd_sof;
333 }
334 //******************************************
335 inline
336 USHORT NODE::get_num_of_in_nds() const
337 {
338  return its_in_nds.get_len();
339 }
340 //******************************************
341 inline
342 const VECTOR<USHORT> & NODE::get_in_nd_degens() const
343 {
344  return its_in_nd_degens;
345 }
346 //******************************************
347 inline
348 const VECTOR<USHORT> & NODE::get_out_nds() const
349 {
350  return its_out_nds;
351 }
352 //******************************************
353 inline
354 VOID NODE::add_out_nd(
355 USHORT nd_id) //in
356 {
357  its_out_nds.insert_last(nd_id);
358 }
359 //******************************************
360 inline
361 VOID NODE::del_out_nd(
362 USHORT nd_id) //in
363 {
364  its_out_nds.extract_at(its_out_nds.loc_of_target(nd_id));
365 }
366 //******************************************
367 inline
368 const SET & NODE::get_active_states() const
369 {
370  return its_active_states;
371 }
372 //******************************************
373 inline
374 VOID NODE::set_active_states(
375 const SET & act_sts) //in
376 {
377  its_active_states = act_sts;
378 }
379 //******************************************
380 inline
381 VOID NODE::empty_act_st_set()
382 {
383  its_active_states.empty();
384 }
385 //******************************************
386 inline
387 USHORT NODE::get_num_of_active_states()
388 {
389  return its_active_states.get_num_of_elems();
390 }
391 //******************************************
392 inline
393 BOOLEAN NODE::is_active_state(
394 USHORT state) //in
395 {
396  return its_active_states.contains(state);
397 }
398 //******************************************
399 inline
400 VOID NODE::activate_state(
401 USHORT state) //in
402 {
403  its_active_states.insert(state);
404 }
405 //******************************************
406 inline
407 VOID NODE::deactivate_state(
408 USHORT state) //in
409 {
410  its_active_states.extract(state);
411 }
412 //******************************************
413 inline
414 VOID NODE::preserve_act_st_set()
415 {
416  its_tempo_active_states = its_active_states;
417 }
418 //******************************************
419 inline
420 USHORT NODE::get_dyn_st() const
421 {
422  return its_dyn_st;
423 }
424 //******************************************
425 inline
426 VOID NODE::set_dyn_st(
427 USHORT dyn_st) //in
428 {
429  its_dyn_st = dyn_st;
430 }
431 //******************************************
432 inline
433 const VECTOR<USHORT> & NODE::get_dyn_in_st()
434 const
435 {
436  return its_dyn_in_st;
437 }
438 //******************************************
439 inline
440 const COMPLEX & NODE::get_dyn_amp()
441 const
442 {
443  ThrowIfNil_(its_dyn_dir_ele_p);
444  return its_dyn_dir_ele_p->its_ele;
445 }
446 //******************************************
447 inline
448 DOUBLE NODE::get_cum_prob(
449 USHORT state) //in
450 const
451 {
452  return its_cum_probs[state];
453 }
454 //******************************************
455 inline
456 VOID NODE::add_to_dyn_st_entry_of_cum_amps(
457 const COMPLEX & net_amp) //in
458 {
459  its_cum_amps[its_dyn_st] += net_amp;
460 }
461 
462 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
463 
464 //******************************************
465 inline
466 C_ND_EFIELD * NODE::get_efield_ptr() const
467 {
468  return its_efield_p;
469 }
470 //******************************************
471 inline
472 VOID NODE::set_efield_ptr(
473 C_ND_EFIELD * efield_p) //in
474 {
475  its_efield_p = efield_p;
476 }
477 //******************************************
478 inline
479 const Point & NODE::get_center() const
480 {
481  return its_center;
482 }
483 //******************************************
484 inline
485 USHORT NODE::get_sel_rad() const
486 {
487  return default_sel_rad;
488 }
489 //******************************************
490 inline
491 USHORT NODE::get_mask_rad() const
492 {
493  return default_mask_rad;
494 }
495 //******************************************
496 inline
497 C_CIRCLE NODE::get_docking_cir(
498 USHORT sub_nd_id) //in
499 {
500  #pragma unused(sub_nd_id)
501  return C_CIRCLE(its_center, get_sel_rad());;
502 }
503 //******************************************
504 inline
505 VOID NODE::add_nd_to_port_glist(
506 USHORT g_nd_id, //in
507 USHORT sub_nd_id) //in
508 {
509 #pragma unused(g_nd_id, sub_nd_id)
510 }
511 //******************************************
512 inline
513 VOID NODE::remove_nd_from_all_port_glists(
514 USHORT g_nd_id) //in
515 {
516 #pragma unused (g_nd_id)
517 }
518 //******************************************
519 inline
520 VOID NODE::renumber_nds_of_port_glists(
521 const UI_MAP & map) //in
522 {}
523 //******************************************
524 inline
525 BOOLEAN NODE::is_selected() const
526 {
527  return its_is_selected;
528 }
529 //******************************************
530 inline
531 BOOLEAN NODE::pt_is_in_sel_cir(
532 const Point & pt) //in
533 {
534  // sel_cir = selection circle
535  return C_CIRCLE(its_center, get_sel_rad()).pt_is_in(pt);
536 }
537 //******************************************
538 inline
539 C_CIRCLE NODE::get_selection_cir()
540 {
541  return C_CIRCLE(its_center, get_sel_rad());
542 }
543 //******************************************
544 inline
545 VOID NODE::set_state_num_for_cap(
546 USHORT state) //in
547 {
548  its_state_num_for_cap = state;
549 }
550 //******************************************
551 inline
552 const RGBColor & NODE::get_color() const
553 {
554  return C_COLORS::its_white;
555 }
556 //******************************************
557 inline
558 VOID NODE::set_color(
559 const RGBColor & color) //in
560 {}
561 //******************************************
562 inline
563 BOOLEAN NODE::has_color()
564 {
565  return false;
566 }
567 //******************************************
568 inline
569 VOID NODE::draw()
570 {
571  // this draws circle, efield and state_cap but not sel_handles
572 }
573 //******************************************
574 inline
575 VOID NODE::undraw()
576 {
577  undraw(default_mask_rad);
578 }
579 //******************************************
580 inline
581 VOID NODE::rotate()
582 {}
583 //******************************************
584 inline
585 SInt16 NODE::get_icon_dir() const
586 {
587  return 0;
588 }
589 //******************************************
590 inline
591 VOID NODE::set_icon_dir(
592 SInt16 icon_dir) //in
593 {}
594 //******************************************
595 inline
596 BOOLEAN NODE::has_icon_dir()
597 {
598  return false;
599 }
600 //******************************************
601 inline
602 VOID NODE::write_net_stream(
603 LStream & net_stream) //i-o
604 {
605  its_tm_amps.write_net_stream(net_stream);
606 }
607 //******************************************
608 inline
609 VOID NODE::read_net_stream(
610 LStream & net_stream) //i-o
611 {
612  its_tm_amps.read_net_stream(net_stream);//this assumes that the Dimensions of trans mat already correct
613 }
614 #endif //_mac_gui_app \\............................................//
615 
616 
617 
618 
619 
Definition: C_MAIN_VIEW.h:24
Definition: STRINGY.h:22
Definition: NODE.h:28
Definition: QB_NET.h:34
Definition: TRANS_MAT.h:21
Definition: DICTIONARY.h:15
Definition: STRETCH_OR_FOLD.h:12
Definition: NODE.h:52
Definition: TRANS_MAT.h:46
Definition: C_PI_WIND.h:18
Definition: C_AMP_GEN.h:10
Definition: SET.h:4
Definition: UI_MAP.h:7
Definition: C_ND_EFIELD.h:6
Definition: C_PORT_RELATED.h:6