fork download
  1. // depends: baja; program; bacnet; control
  2. import javax.baja.nre.util.*;
  3. import javax.baja.sys.*;
  4. import javax.baja.status.*;
  5. import javax.baja.util.*;
  6. import javax.baja.job.*;
  7. import javax.baja.naming.*;
  8. import javax.baja.space.*;
  9. import javax.baja.collection.*;
  10. import javax.baja.bacnet.*;
  11. import javax.baja.control.*;
  12. import javax.baja.bacnet.enums.*;
  13. import javax.baja.bacnet.point.*;
  14. import javax.baja.bacnet.datatypes.*;
  15. import com.tridium.program.*;
  16. import java.util.*;
  17. import java.util.InputMismatchException;
  18.  
  19. public class RobotImpl
  20. extends Robot
  21. {
  22. public void run()
  23. throws Exception
  24. {
  25. //update this ord to the starting location in your station
  26. //when run this will iterate through children from this location
  27. //down to all leaf nodes
  28. BOrd startOrd = BOrd.make("station:|slot:/Drivers/BacnetNetwork/AHUs/AHU1/AHU1Test");
  29. BComponent startComp = (BComponent)startOrd.resolve().get();
  30. process(startComp);
  31. }
  32. public void process(BComponent c)
  33. throws Exception
  34. {
  35. BComponent[] kids = c.getChildComponents();
  36. //probably don"t want to rearrange all sub components from the starting ord
  37. //this checks for standard BFolder components and only arranges components under the folders
  38. //should possibly change this for a specific driver folder type or remove the if statement.
  39. int len = kids.length;
  40. int left_y = 1;
  41. int center_y = 1;
  42. int right_y = 1;
  43. int far_right_y = 1;
  44.  
  45. //starting x,y coordinates
  46. int x = 0;
  47. int y = 1;
  48.  
  49. //configures x and y spacing between glyphs
  50. int ySpacing = 1;
  51.  
  52. if(c.getType().is(BBacnetPointDeviceExt.TYPE)){
  53.  
  54. //configure default horizontal column spacing
  55. int left_x = 3;
  56. int center_x = 83;
  57. int right_x = 113;
  58. int far_right_x = 153;
  59.  
  60. BLink[] links;
  61. int lenlinks;
  62.  
  63. BWsAnnotation last = null;
  64. BWsAnnotation update = null;
  65.  
  66. //sort the array of components using the inner class NameComparator, which sorts components alphabetically by names
  67. try{
  68. Arrays.sort(kids, new IdComparator());
  69. } catch (Exception e) {
  70. }
  71.  
  72. for(int i=0; i<len; i++) {
  73. int ordinal = 0;
  74. try{
  75. BValue point = kids[i].get("proxyExt");
  76. BComponent ext = point.asComponent();
  77. BSimple simpleId = ext.get("objectId").asSimple();
  78.  
  79. if(simpleId.toString().contains("analogInput")) {
  80. ordinal = 1;
  81. update = BWsAnnotation.make(left_x, left_y);
  82. }
  83. if(simpleId.toString().contains("analogOutput")) {
  84. ordinal = 2;
  85. update = BWsAnnotation.make(right_x, right_y);
  86. }
  87. if(simpleId.toString().contains("analogValue")) {
  88. ordinal = 3;
  89. update = BWsAnnotation.make(center_x, center_y);
  90. }
  91. if(simpleId.toString().contains("binaryInput")){
  92. ordinal = 4;
  93. update = BWsAnnotation.make(left_x, left_y);
  94. }
  95. if(simpleId.toString().contains("binaryOutput")){
  96. ordinal = 5;
  97. update = BWsAnnotation.make(far_right_x, far_right_y);
  98. }
  99. if(simpleId.toString().contains("binaryValue")){
  100. ordinal = 6;
  101. update = BWsAnnotation.make(center_x, center_y);
  102. }
  103. if(ordinal == 0){
  104. update = BWsAnnotation.make(center_x, center_y);
  105. }
  106. }
  107. update = BWsAnnotation.make(center_x, center_y);
  108. }
  109.  
  110. //3 handles title and bottom section of glyph
  111. int pinnedSlots = 3;
  112. if(kids[i].get("wsAnnotation")!=null)
  113. {
  114. //there is currently some wsAnnotation
  115. BWsAnnotation current = (BWsAnnotation)kids[i].get("wsAnnotation");
  116. current = BWsAnnotation.merge(current, update);
  117. kids[i].set("wsAnnotation", current);
  118. last = current;
  119. }
  120. else
  121. {
  122. //no current wsAnnotation so just apply
  123. kids[i].add("wsAnnotation", update);
  124. last = update;
  125. }
  126.  
  127. Slot[] slots = kids[i].getSlotsArray();
  128. for(int k=0; k<slots.length; k++){
  129. //account for each pinned slot because it adds to the height of the glyph
  130. if((kids[i].getFlags(slots[k]) & Flags.SUMMARY)!=0) pinnedSlots = pinnedSlots+1;
  131. if((kids[i].getFlags(slots[k]) & Flags.COMPOSITE)!=0) pinnedSlots = pinnedSlots+1;
  132. }
  133.  
  134.  
  135.  
  136. //update x,y coordinates for next component
  137. switch(ordinal){
  138. case 1:
  139. x = left_x;
  140. y = left_y + ySpacing + pinnedSlots;
  141. left_y = y;
  142. break;
  143.  
  144. case 2:
  145. x = right_x;
  146. y = right_y + ySpacing + pinnedSlots;
  147. right_y = y;
  148. break;
  149.  
  150. case 3:
  151. links = kids[i].getLinks();
  152. lenlinks = links.length;
  153. if(lenlinks == 0) {
  154. x = center_x;
  155. y = center_y + ySpacing + pinnedSlots;
  156. center_y = y;
  157. }
  158. break;
  159.  
  160. case 4:
  161. x = left_x;
  162. y = left_y + ySpacing + pinnedSlots;
  163. left_y = y;
  164. break;
  165.  
  166. case 5:
  167. x = far_right_x;
  168. y = far_right_y + ySpacing + pinnedSlots;
  169. far_right_y = y;
  170. break;
  171.  
  172. case 6:
  173. links = kids[i].getLinks();
  174. lenlinks = links.length;
  175. if(lenlinks == 0){
  176. x = center_x;
  177. y = center_y + ySpacing + pinnedSlots;
  178. center_y = y;
  179. }
  180. break;
  181.  
  182. default:
  183. x = center_x;
  184. y = center_y + ySpacing + pinnedSlots;
  185. center_y = y;
  186. }
  187. }
  188. for(int i=0; i<len; i++) {
  189. // Figure out resorting for knobs
  190. try{
  191. int temp_y = 0;
  192. int temp_x = 11;
  193. int recurse_knobs = 0;
  194. int depth = 0;
  195.  
  196.  
  197. int kc = kids[i].getKnobCount();
  198. if(kc > 0){
  199. //log.println(kids[i].getName());
  200. //log.println(kc);
  201. //log.println();
  202. for(int kk=0; kk<kc; kk++){
  203. Knob knob = kids[i].getKnobs()[kk];
  204. BComponent ksource = knob.getSourceComponent();
  205. BComponent kdest = knob.getTargetComponent();
  206. BWsAnnotation bw_dest = (BWsAnnotation)kdest.get("wsAnnotation");
  207. BWsAnnotation bw_source = (BWsAnnotation)ksource.get("wsAnnotation");
  208.  
  209. //account for each pinned slot because it adds to the height of the glyph
  210. int temp_pinnedSlots = 3;
  211. Slot[] kslots = kdest.getSlotsArray();
  212. for(int k1=0; k1<kslots.length; k1++){
  213. if((kdest.getFlags(kslots[k1]) & Flags.SUMMARY)!=0) temp_pinnedSlots = temp_pinnedSlots+1;
  214. if((kdest.getFlags(kslots[k1]) & Flags.COMPOSITE)!=0) temp_pinnedSlots = temp_pinnedSlots+1;
  215. }
  216. temp_y = temp_y + ySpacing + temp_pinnedSlots;
  217.  
  218.  
  219. depth = recurseLinks(ksource, 0);
  220. log.println(depth);
  221.  
  222. temp_x = temp_x + 10*depth;
  223. BWsAnnotation bw_new = BWsAnnotation.make(temp_x+3,temp_y);
  224. BWsAnnotation bw_current = (BWsAnnotation)ksource.get("wsAnnotation");
  225.  
  226. bw_current = BWsAnnotation.merge(bw_current, bw_new);
  227. kdest.set("wsAnnotation",bw_current);
  228. }
  229. }
  230. }
  231. catch (Exception e) {
  232. }
  233. }
  234. log.println("Rearranged wiresheet: " + c.getSlotPathOrd());
  235. }
  236. // recurse
  237. for(int j=0; j<len; j++){
  238. process(kids[j]);
  239. }
  240. }
  241. /////////////////////////////
  242. // inner classes
  243. /////////////////////////////
  244. private static int recurseLinks(BComponent clink, int n_link)
  245. {
  246. BLink[] clinks = clink.getLinks();
  247. int maxD = 0;
  248.  
  249. String tabString = "";
  250. if(clinks.length > 0){
  251.  
  252. for(int tab = 0; tab < n_link; tab++){
  253. tabString = tabString + "\t";
  254. }
  255.  
  256. for(int cL = 0; cL < clinks.length; cL++){
  257. //log.println("\t\t"+clinks[cL].getSourceComponent().getName());
  258. if(n_link < 5){
  259. maxD = recurseLinks(clinks[cL].getSourceComponent(), n_link);
  260. }
  261. if(maxD > n_link){
  262. n_link = maxD;
  263. }
  264. }
  265. }
  266. return n_link+1;
  267. }
  268.  
  269.  
  270. class NameComparator implements Comparator
  271. {
  272. public int compare(Object a1, Object a2)
  273. {
  274. String a1Name = ((BComponent)a1).getName();
  275. String a2Name = ((BComponent)a2).getName();
  276. return a1Name.compareToIgnoreCase(a2Name);
  277. }
  278. }
  279.  
  280. class IdComparator implements Comparator
  281. {
  282. public int compare(Object a1, Object a2)
  283. {
  284. try{
  285. BComponent[] a1ca = ((BComponent)a1).getChildComponents();
  286. int a1c = a1ca.length;
  287. BComponent[] a2ca = ((BComponent)a2).getChildComponents();
  288. int a2c = a2ca.length;
  289.  
  290. if(a1c > 0 && a2c > 0){
  291. // Sort By Number
  292. BComponent a1_ext = ((BComponent)a1).getChildComponents()[0];
  293. BSimple a1Simple = a1_ext.get("objectId").asSimple();
  294. String a1num = a1Simple.toString().replaceAll("[^0-9.]", "");
  295. int a1int = Integer.parseInt(a1num);
  296.  
  297.  
  298. BComponent a2_ext = ((BComponent)a2).getChildComponents()[0];
  299. BSimple a2Simple = a2_ext.get("objectId").asSimple();
  300. String a2num = a2Simple.toString().replaceAll("[^0-9.]", "");
  301. int a2int = Integer.parseInt(a2num);
  302.  
  303.  
  304. return a1int - a2int;
  305. } else {
  306. // Sort By Name
  307. String a1Name = ((BComponent)a1).getName();
  308. String a2Name = ((BComponent)a2).getName();
  309. return a1Name.compareTo(a2Name);
  310. }
  311. }
  312. catch (Exception e){
  313. return 0;
  314. }
  315. }
  316. }
  317. }
  318.  
  319.  
  320. // Rev 0: initial
  321. // Rev 1: Far Right Added
  322. // Rev 2: Number Sort replaced Name Sort; Far Left Added
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:19: error: class RobotImpl is public, should be declared in a file named RobotImpl.java
public class RobotImpl
       ^
Main.java:2: error: package javax.baja.nre.util does not exist
import javax.baja.nre.util.*;
^
Main.java:3: error: package javax.baja.sys does not exist
import javax.baja.sys.*;
^
Main.java:4: error: package javax.baja.status does not exist
import javax.baja.status.*;
^
Main.java:5: error: package javax.baja.util does not exist
import javax.baja.util.*; 
^
Main.java:6: error: package javax.baja.job does not exist
import javax.baja.job.*;
^
Main.java:7: error: package javax.baja.naming does not exist
import javax.baja.naming.*;
^
Main.java:8: error: package javax.baja.space does not exist
import javax.baja.space.*;
^
Main.java:9: error: package javax.baja.collection does not exist
import javax.baja.collection.*; 
^
Main.java:10: error: package javax.baja.bacnet does not exist
import javax.baja.bacnet.*;
^
Main.java:11: error: package javax.baja.control does not exist
import javax.baja.control.*;
^
Main.java:12: error: package javax.baja.bacnet.enums does not exist
import javax.baja.bacnet.enums.*;
^
Main.java:13: error: package javax.baja.bacnet.point does not exist
import javax.baja.bacnet.point.*;
^
Main.java:14: error: package javax.baja.bacnet.datatypes does not exist
import javax.baja.bacnet.datatypes.*;
^
Main.java:15: error: package com.tridium.program does not exist
import com.tridium.program.*; 
^
Main.java:20: error: cannot find symbol
  extends Robot
          ^
  symbol: class Robot
Main.java:32: error: cannot find symbol
  public void process(BComponent c)
                      ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:245: error: cannot find symbol
  private static int recurseLinks(BComponent clink, int n_link)
                                  ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:28: error: cannot find symbol
    BOrd startOrd = BOrd.make("station:|slot:/Drivers/BacnetNetwork/AHUs/AHU1/AHU1Test");
    ^
  symbol:   class BOrd
  location: class RobotImpl
Main.java:28: error: cannot find symbol
    BOrd startOrd = BOrd.make("station:|slot:/Drivers/BacnetNetwork/AHUs/AHU1/AHU1Test");
                    ^
  symbol:   variable BOrd
  location: class RobotImpl
Main.java:29: error: cannot find symbol
    BComponent startComp = (BComponent)startOrd.resolve().get();
    ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:29: error: cannot find symbol
    BComponent startComp = (BComponent)startOrd.resolve().get();
                            ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:35: error: cannot find symbol
    BComponent[] kids = c.getChildComponents();
    ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:52: error: cannot find symbol
    if(c.getType().is(BBacnetPointDeviceExt.TYPE)){
                      ^
  symbol:   variable BBacnetPointDeviceExt
  location: class RobotImpl
Main.java:60: error: cannot find symbol
      BLink[] links;
      ^
  symbol:   class BLink
  location: class RobotImpl
Main.java:63: error: cannot find symbol
      BWsAnnotation last = null;
      ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:64: error: cannot find symbol
      BWsAnnotation update = null;
      ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:75: error: cannot find symbol
          BValue point = kids[i].get("proxyExt");
          ^
  symbol:   class BValue
  location: class RobotImpl
Main.java:76: error: cannot find symbol
          BComponent ext = point.asComponent();
          ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:77: error: cannot find symbol
          BSimple simpleId = ext.get("objectId").asSimple();
          ^
  symbol:   class BSimple
  location: class RobotImpl
Main.java:81: error: cannot find symbol
            update = BWsAnnotation.make(left_x, left_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:85: error: cannot find symbol
            update = BWsAnnotation.make(right_x, right_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:89: error: cannot find symbol
            update = BWsAnnotation.make(center_x, center_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:93: error: cannot find symbol
            update = BWsAnnotation.make(left_x, left_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:97: error: cannot find symbol
            update = BWsAnnotation.make(far_right_x, far_right_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:101: error: cannot find symbol
            update = BWsAnnotation.make(center_x, center_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:104: error: cannot find symbol
            update = BWsAnnotation.make(center_x, center_y);
                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:108: error: cannot find symbol
          update = BWsAnnotation.make(center_x, center_y);
                   ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:116: error: cannot find symbol
          BWsAnnotation current = (BWsAnnotation)kids[i].get("wsAnnotation");
          ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:116: error: cannot find symbol
          BWsAnnotation current = (BWsAnnotation)kids[i].get("wsAnnotation");
                                   ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:117: error: cannot find symbol
          current = BWsAnnotation.merge(current, update);
                    ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:128: error: cannot find symbol
        Slot[] slots = kids[i].getSlotsArray();
        ^
  symbol:   class Slot
  location: class RobotImpl
Main.java:131: error: cannot find symbol
          if((kids[i].getFlags(slots[k]) & Flags.SUMMARY)!=0) pinnedSlots = pinnedSlots+1;
                                           ^
  symbol:   variable Flags
  location: class RobotImpl
Main.java:132: error: cannot find symbol
          if((kids[i].getFlags(slots[k]) & Flags.COMPOSITE)!=0) pinnedSlots = pinnedSlots+1;
                                           ^
  symbol:   variable Flags
  location: class RobotImpl
Main.java:204: error: cannot find symbol
              Knob knob = kids[i].getKnobs()[kk];
              ^
  symbol:   class Knob
  location: class RobotImpl
Main.java:205: error: cannot find symbol
              BComponent ksource = knob.getSourceComponent();
              ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:206: error: cannot find symbol
              BComponent kdest = knob.getTargetComponent();
              ^
  symbol:   class BComponent
  location: class RobotImpl
Main.java:207: error: cannot find symbol
              BWsAnnotation bw_dest = (BWsAnnotation)kdest.get("wsAnnotation");
              ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:207: error: cannot find symbol
              BWsAnnotation bw_dest = (BWsAnnotation)kdest.get("wsAnnotation");
                                       ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:208: error: cannot find symbol
              BWsAnnotation bw_source = (BWsAnnotation)ksource.get("wsAnnotation");
              ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:208: error: cannot find symbol
              BWsAnnotation bw_source = (BWsAnnotation)ksource.get("wsAnnotation");
                                         ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:212: error: cannot find symbol
              Slot[] kslots = kdest.getSlotsArray();
              ^
  symbol:   class Slot
  location: class RobotImpl
Main.java:214: error: cannot find symbol
                if((kdest.getFlags(kslots[k1]) & Flags.SUMMARY)!=0) temp_pinnedSlots = temp_pinnedSlots+1;
                                                 ^
  symbol:   variable Flags
  location: class RobotImpl
Main.java:215: error: cannot find symbol
                if((kdest.getFlags(kslots[k1]) & Flags.COMPOSITE)!=0) temp_pinnedSlots = temp_pinnedSlots+1;
                                                 ^
  symbol:   variable Flags
  location: class RobotImpl
Main.java:221: error: cannot find symbol
              log.println(depth);
              ^
  symbol:   variable log
  location: class RobotImpl
Main.java:224: error: cannot find symbol
              BWsAnnotation bw_new = BWsAnnotation.make(temp_x+3,temp_y);
              ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:224: error: cannot find symbol
              BWsAnnotation bw_new = BWsAnnotation.make(temp_x+3,temp_y);
                                     ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:225: error: cannot find symbol
              BWsAnnotation bw_current = (BWsAnnotation)ksource.get("wsAnnotation");
              ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:225: error: cannot find symbol
              BWsAnnotation bw_current = (BWsAnnotation)ksource.get("wsAnnotation");
                                          ^
  symbol:   class BWsAnnotation
  location: class RobotImpl
Main.java:227: error: cannot find symbol
              bw_current = BWsAnnotation.merge(bw_current, bw_new);
                           ^
  symbol:   variable BWsAnnotation
  location: class RobotImpl
Main.java:235: error: cannot find symbol
      log.println("Rearranged wiresheet: " + c.getSlotPathOrd());
      ^
  symbol:   variable log
  location: class RobotImpl
Main.java:247: error: cannot find symbol
    BLink[] clinks = clink.getLinks();
    ^
  symbol:   class BLink
  location: class RobotImpl
Main.java:275: error: cannot find symbol
      String a1Name = ((BComponent)a1).getName();
                        ^
  symbol:   class BComponent
  location: class RobotImpl.NameComparator
Main.java:276: error: cannot find symbol
      String a2Name = ((BComponent)a2).getName();
                        ^
  symbol:   class BComponent
  location: class RobotImpl.NameComparator
Main.java:286: error: cannot find symbol
        BComponent[] a1ca = ((BComponent)a1).getChildComponents();
        ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:286: error: cannot find symbol
        BComponent[] a1ca = ((BComponent)a1).getChildComponents();
                              ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:288: error: cannot find symbol
        BComponent[] a2ca = ((BComponent)a2).getChildComponents();
        ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:288: error: cannot find symbol
        BComponent[] a2ca = ((BComponent)a2).getChildComponents();
                              ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:293: error: cannot find symbol
          BComponent a1_ext = ((BComponent)a1).getChildComponents()[0];
          ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:293: error: cannot find symbol
          BComponent a1_ext = ((BComponent)a1).getChildComponents()[0];
                                ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:294: error: cannot find symbol
          BSimple a1Simple = a1_ext.get("objectId").asSimple();
          ^
  symbol:   class BSimple
  location: class RobotImpl.IdComparator
Main.java:299: error: cannot find symbol
          BComponent a2_ext = ((BComponent)a2).getChildComponents()[0];
          ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:299: error: cannot find symbol
          BComponent a2_ext = ((BComponent)a2).getChildComponents()[0];
                                ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:300: error: cannot find symbol
          BSimple a2Simple = a2_ext.get("objectId").asSimple();
          ^
  symbol:   class BSimple
  location: class RobotImpl.IdComparator
Main.java:308: error: cannot find symbol
          String a1Name = ((BComponent)a1).getName();
                            ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
Main.java:309: error: cannot find symbol
          String a2Name = ((BComponent)a2).getName();
                            ^
  symbol:   class BComponent
  location: class RobotImpl.IdComparator
76 errors
stdout
Standard output is empty