superedit-GIS_OPT_STRUCTURES2.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. <?php
  2. //
  3. // synchronizacja do serwera postgres GIS
  4. //
  5. include_once('se-lib/DB_Dump.php');
  6. include_once('se-lib/UsersHelper.php');
  7. class GIS_OPT_STRUCTURES2 {
  8. function __construct() {
  9. $this->width=800;
  10. }
  11. function init() {
  12. $this->graph = new stdClass();
  13. $this->graph->htmlID = 'graph_proces_id_' . $id_proces;
  14. $this->graph->procesTreeFlat = array();
  15. $this->graph->procesTreeGoto = array();
  16. $this->graph->treeItems = array();
  17. $this->graph->elements = new stdClass();
  18. $this->graph->elements->nodes = array();
  19. $this->graph->elements->edges = array();
  20. }
  21. function set_mysql_zas_id($mysql_zas_id) {
  22. $this->mysql_zas_id=$mysql_zas_id;
  23. }
  24. function set_gis_zas_id($gis_zas_id) {
  25. $this->gis_zas_id=$gis_zas_id;
  26. $this->gdb=DB::getDB($this->gis_zas_id);
  27. }
  28. function get_opt_objects($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$ids_ok) {
  29. $sql='select \''.$src_table.'\' as src_table , "'.$src_index.'" as src_index ';
  30. if(!empty($src_name)) $sql.=', "'.$src_name.'" as src_name ';
  31. $sql.=', "'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" '.$limit.' ;';
  32. $res=$this->gdb->query($sql);
  33. while($h=$this->gdb->fetch($res)) {
  34. if(!empty($limit)) {
  35. //bierzemy wszystkie rekordy bo byl limit
  36. $arr[]=$h;
  37. $this->tables->$src_table->src_index[]=$h->src_index;
  38. $this->tables->$src_table->data[$h->src_index]=$h;
  39. } else {
  40. //tylko te rekordy dla ktorych byly powiazania
  41. if(in_array($h->parent_table_id, $this->tables->$parent_table->src_index)) {
  42. $this->tables->$src_table->src_index[]=$h->src_index;
  43. // echo "<br> <font color=green>id ".$h->parent_table_id." IS found in ".$parent_table." parent table</font>";
  44. $arr[]=$h;
  45. $this->tables->$src_table->data[$h->src_index]=$h;
  46. // $this->tables->$src_table->childs[$h->src_index]=array();
  47. if(!in_array($h->src_index, $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table])) {
  48. $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
  49. $this->tables->$parent_table->childs[$h->parent_table_id]->objects[]=$src_table."_".$h->src_index;
  50. $this->tables->$parent_table->child_recurs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
  51. // echo "<br> Table to ".$src_table." a parent to ".$parent_table;
  52. }
  53. } //else echo "<br> id ".$h->parent_table_id." not found in ".$parent_table." parent table";
  54. }
  55. }
  56. return $arr;
  57. }
  58. function get_opt_objects_parent($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$child_table,$child_joinfield,$child_index){
  59. $i=0;
  60. $where_in=implode(",", $this->tables->$child_table->src_index);
  61. $sql='select \''.$src_table.'\' as src_table , t1."'.$src_index.'" as src_index ';
  62. if(!empty($src_name)) $sql.=', t1."'.$src_name.'" as src_name ';
  63. $sql.=', t1."'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" as t1
  64. inner join "'.$child_table.'" as t2 on t1."'.$src_index.'"=t2."'.$child_joinfield.'"
  65. where t2."'.$child_index.'" in ('.$where_in.') ;';
  66. // echo "<br> sql: ".$sql;
  67. $res=$this->gdb->query($sql);
  68. while($h=$this->gdb->fetch($res)) {
  69. $i++;
  70. // if($i>5) continue;
  71. if(!in_array($h->src_index, $this->tables->$src_table->src_index)) {
  72. $this->tables->$src_table->src_index[]=$h->src_index;
  73. $this->tables->$src_table->data[$h->src_index]=$h;
  74. $arr[]=$h;
  75. }
  76. if($h->parent_table_id)
  77. if(!in_array($h->src_index, $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table])) {
  78. $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
  79. $this->tables->$parent_table->childs[$h->parent_table_id]->objects[]=$src_table."_".$h->src_index;
  80. }
  81. // echo "<br> (".$src_table.") child_joinfield is ".$child_joinfield." from ".$parent_table." val is ".$h->parent_table_id;
  82. }
  83. return $arr;
  84. }
  85. function set_layer_deepth($src_table,$deepth) {
  86. $this->tables->$src_table->deepth=$deepth;
  87. }
  88. function get_layer_deepth($src_table) {
  89. return $this->tables->$src_table->deepth;
  90. }
  91. function invert_layer_deepth() {
  92. $deepth=0;
  93. foreach($this->tables as $src_table=>$obj_data) {
  94. if($obj_data->deepth>$deepth) $deepth=$obj_data->deepth;
  95. }
  96. foreach($this->tables as $src_table=>$obj_data) {
  97. $this->tables->$src_table->deepth=$deepth-$this->tables->$src_table->deepth;
  98. //echo "<br>182 Deepht".$deepth." w ".$src_table;
  99. }
  100. }
  101. //rekursywne nadanie wszystkim obiektom powiazan/sciezek, aby mozna bylo je przesortowac i poukladac po kolei - aby obiekty root znaly swoje powiazania
  102. function find_connect_paths($src_table,$deepth=0) {
  103. self::set_layer_deepth($src_table,$deepth);
  104. $deepth++;
  105. //najpierw zjezdzamy w dol po dzieciach dajac znac na sam dol o ID nadrzenego
  106. //echo "<hr> odpalam funkcje path dla ".$src_table;
  107. //for($i = 1; $i <= 10; $i++) {
  108. foreach($this->tables->$src_table->childs as $id_parent=>$child) {
  109. // echo "<br> Szumam dzieci..";
  110. foreach($child->tables as $table=>$child_) {
  111. foreach($child_ as $id ) {
  112. // echo "<br> Wpisalem do dziecka ".$table." , ze parent is ".$id_parent." /".$child_;echo " = ".$id;
  113. $this->tables->$table->parents->$src_table->tables[$id][]=$id_parent;
  114. if(!in_array($table, $tables_to_connect)) $tables_to_connect[]=$table;
  115. }
  116. }
  117. foreach($this->tables->$src_table->parents as $parent_table=>$parent_data) {
  118. //echo "<br> 140: parent_table= ".$parent_table;
  119. foreach($parent_data->tables as $src_id=>$parents) {
  120. // echo " 142: (".$src_id.")";
  121. foreach($parents as $dst_id) {
  122. foreach($this->tables->$src_table->childs[$src_id]->tables as $child_table=>$child_id_arr) {
  123. foreach($child_id_arr as $child_id) {
  124. // if(!in_array($dst_id, $this->tables->$child_table->parents->$parent_table->tables[$child_id])) $this->tables->$child_table->parents->$parent_table->tables[$child_id][]=$dst_id;
  125. self::notify_child_node_about_parents($child_table,$parent_table,$child_id,$dst_id);
  126. self::add_link_from_recurse_struct($child_table,$parent_table,$child_id);
  127. $this->tables->$parent_table->child_recurs[$dst_id]->tables[$child_table][$child_id]=1;
  128. // $this->tables->$parent_table->size[$dst_id]->all++;
  129. }
  130. }
  131. //$this->tables->$src_table->parents->$parent_table->tables[$id][]=$id_parent;
  132. }
  133. }
  134. }
  135. }
  136. // }
  137. //potem patrzymy czy wystepuje jakis obiekt naszego typu w dol, jezeli tak, to zapisujemy to , ze ma polaczenie przez obiekty podrzedne
  138. foreach($tables_to_connect as $table) {
  139. self::find_connect_paths($table,$deepth);
  140. }
  141. }
  142. //funkcja informuje dzieci obiektu o tym, jakich ma rodzicow
  143. function notify_child_node_about_parents($child_table,$parent_table,$child_id,$dst_id) {
  144. if(!in_array($dst_id, $this->tables->$child_table->parents->$parent_table->tables[$child_id])) {
  145. //DEBUG_S(-3,"Nadpisze parenta dla tabeli ".$parent_table."(".$dst_id.") w tabeli ".$src_table." child ".$child_table." = src ".$src_id." id parent ".$id_parent,null,__FILE__,__FUNCTION__,__LINE__);
  146. $this->tables->$child_table->parents->$parent_table->tables[$child_id][]=$dst_id;
  147. }
  148. }
  149. //funkcja informujaca, ze opt_wezly maja ze soba powiazania w links, na postawie tego, ze gdzies na dole wlokna ida poprzez strukture do tych wezlow
  150. function add_link_from_recurse_struct($child_table,$parent_table,$child_id) {
  151. if(count($this->tables->$child_table->parents->$parent_table->tables[$child_id])>1) {
  152. DEBUG_S(3,'Moge powiazac tabele '.$parent_table.' na podstawie info z '.$child_table,$this->tables->$child_table->parents->$parent_table->tables[$child_id],__FILE__,__FUNCTION__,__LINE__);
  153. $first=false;
  154. foreach($this->tables->$child_table->parents->$parent_table->tables[$child_id] as $link) {
  155. if(!$first) $first=$link;
  156. else {
  157. $this->tables->$parent_table->links->$first->$link=true;
  158. $this->tables->$parent_table->links->$link->$first=true;
  159. }
  160. }
  161. }
  162. }
  163. function set_layer_coords($src_table,$start_x,$start_y) {
  164. $this->tables->$src_table->cursor->x=$start_x;
  165. $this->tables->$src_table->cursor->y=$start_y;
  166. }
  167. function offset_layer_coords($src_table,$x,$y) {
  168. $this->tables->$src_table->cursor->x+=$x;
  169. $this->tables->$src_table->cursor->y+=$y;
  170. }
  171. function set_obj_coord_by_layer($src_table,$obj) {
  172. $this->tables->$src_table->obj_cursor[$obj]->x=$this->tables->$src_table->cursor->x;
  173. $this->tables->$src_table->obj_cursor[$obj]->y=$this->tables->$src_table->cursor->y;
  174. }
  175. function set_obj_size_width($src_table,$obj,$width) {
  176. $this->tables->$src_table->obj_width[$obj]=$width+20;
  177. }
  178. function set_obj_min_y_size($src_table,$obj,$size) {
  179. $this->tables->$src_table->min_y_size[$obj]=$size;
  180. }
  181. function set_obj_size_width_by_min_y_size($src_table,$obj) {
  182. self::set_obj_size_width($src_table,$obj,$this->tables->$src_table->min_x_size[$obj]);
  183. }
  184. function set_obj_size_width_by_parent($parent_table,$parent_obj,$src_table,$obj,$opts) {
  185. if(isset($opts['ratio']))
  186. $this->tables->$src_table->obj_width[$obj]=$this->tables->$parent_table->obj_width[$parent_obj]*$opts['ratio'];
  187. }
  188. function get_obj_size_width($src_table,$obj) {
  189. return $this->tables->$src_table->obj_width[$obj];
  190. }
  191. function set_obj_coords_by_parent($parent_table,$parent_obj,$src_table,$obj) {
  192. echo "\n// set_obj_coords_by_parent (".$parent_table.",".$parent_obj.",".$src_table.",".$obj.") ";
  193. $this->tables->$src_table->obj_cursor[$obj]->x=$this->tables->$parent_table->obj_cursor[$parent_obj]->x+10;
  194. $this->tables->$src_table->obj_cursor[$obj]->y=$this->tables->$parent_table->obj_cursor[$parent_obj]->y+10;
  195. echo " - i setted ".$this->tables->$parent_table->obj_cursor[$parent_obj]->x."/ ".$this->tables->$parent_table->obj_cursor[$parent_obj]->y;
  196. }
  197. function calculate_obj_size_by_child_recurs($src_table,$obj) {
  198. $count=0;$width=0;
  199. echo "\n//Licze size dla ".$src_table.' / '.$obj;
  200. foreach($this->tables->$src_table->child_recurs[$obj]->tables as $child_table=>$child_table_arr) {
  201. if(self::get_type_table($child_table)=='Connect') continue;
  202. echo " - ".$child_table;
  203. $count+=count($child_table_arr)*20;
  204. if(strlen(self::get_obj_name($src_table,$obj)) > $width) $width=strlen(self::get_obj_name($src_table,$obj))*5;
  205. }
  206. $count_local=count($this->tables->$src_table->childs[$obj]->objects)*20;
  207. if($width<100) $width=100;
  208. if($count_local>$count) $count=$count_local;
  209. $count=$count+15+self::get_layer_deepth($src_table)*15;
  210. // $this->tables->$src_table->min_y_size[$obj]=$count;
  211. self::set_obj_min_y_size($src_table,$obj,$count);
  212. $this->tables->$src_table->min_x_size[$obj]=$width;
  213. }
  214. function get_obj_size_by_child_recurs($src_table,$obj) {
  215. echo "\n // get_obj_size_by_child_recurs dla ".$src_table." wynosi ".$obj." = ".$this->tables->$src_table->min_y_size[$obj];
  216. return $this->tables->$src_table->min_y_size[$obj];
  217. }
  218. function get_obj_name($src_table,$obj) {
  219. return $this->tables->$src_table->data[$obj]->src_name;
  220. }
  221. //funkcja do zwracania pierwszego obiektu wg roznych kryteriow : najmniej_powiazan, powiazanie z poprzednim, etc...
  222. function get_next_obj($src_table,$situation) {
  223. echo "\n /* 313: Situation <-- ";
  224. print_r($situation);
  225. print_r($this->get_next_obj);
  226. echo "*/\n";
  227. if($situation->count>1) {
  228. if($situation->min_links==0) $ret=$situation->min_links_id;
  229. else if($situation->min_links==1) { echo "\n// 320:Sytuacja min_links==1";
  230. if(isset($this->get_next_obj->last_obj)) {
  231. if(isset($this->get_next_obj->last_obj_count)) {
  232. echo "\n //324::szukamy kogos, do kogo mamy podpiecie ";
  233. $var=$this->get_next_obj->last_obj;
  234. foreach(self::get_next_obj_unlayed($src_table) as $obj) {
  235. if(isset($this->tables->$src_table->links->$obj->$var))
  236. if(in_array($obj, $situation->min_links_id_arr))
  237. $ret=$obj;
  238. }
  239. } else {
  240. //poprzedni nie mial zadnego powiazania
  241. $ret=$situation->min_links_id;
  242. }
  243. }
  244. }
  245. } else $ret=$situation->id;
  246. $this->get_next_obj->last_obj=$ret;
  247. if(!isset($ret)) $ret=$situation->id;
  248. return $ret;
  249. }
  250. function analyze_arrange_situation($src_table) {
  251. $var=$this->get_next_obj->last_obj;
  252. if(isset($this->get_next_obj->last_obj)) {
  253. if(isset($this->tables->$src_table->links->$var)) {
  254. echo "\n // 354: analyze_arrange_situation dla ".$this->get_next_obj->last_obj." ";
  255. $co=0;
  256. foreach($this->tables->$src_table->links->$var as $cos=>$cos_) {
  257. $co++;
  258. }
  259. $this->get_next_obj->last_obj_count=$co;
  260. } else echo "\n //353: no exists links for ".$var;
  261. }
  262. $max_links=0;
  263. foreach(self::get_next_obj_unlayed($src_table) as $obj) {
  264. $cnt[]=$obj;
  265. echo "\n //334: max_links=".$max_links." id ".$max_links_id." min is ".$min_links." id is ".$min_links_id." obj[".$obj."]";
  266. $count=0;
  267. if(isset($this->tables->$src_table->links->$obj)) {
  268. foreach($this->tables->$src_table->links->$obj as $link) {
  269. $count++;
  270. }
  271. }
  272. echo "\n// 315:jeszcze nie pojawil sie ".$src_table." [".$obj."] count: ".$count;
  273. if(isset($max_links)) {
  274. if($count>$max_links) {
  275. $max_links=$count;
  276. $max_links_id=$obj;
  277. unset($max_links_id_arr);
  278. $max_links_id_arr[]=$obj;
  279. } else if($count==$max_links) $max_links_id_arr[]=$obj;
  280. }
  281. if(isset($min_links)) {
  282. if($count<$min_links) {
  283. $min_links=$count;
  284. $min_links_id=$obj;
  285. unset($min_links_id_arr);
  286. $min_links_id_arr[]=$obj;
  287. } else if($count==$min_links) $min_links_id_arr[]=$obj;
  288. }
  289. if(!isset($min_links)) {
  290. $min_links=$count;$min_links_id=$obj;$min_links_id_arr[]=$obj;
  291. }
  292. if(!isset($max_links)) {
  293. $max_links=$count;$max_links_id=$obj;$max_links_id_arr[]=$obj;
  294. }
  295. }
  296. $ret->min_links=$min_links;
  297. $ret->max_links=$max_links;
  298. $ret->min_links_id=$min_links_id;
  299. $ret->max_links_id=$max_links_id;
  300. $ret->max_links_id_arr=$max_links_id_arr;
  301. $ret->min_links_id_arr=$min_links_id_arr;
  302. $ret->count=count($cnt);
  303. $ret->id=$cnt[0];
  304. return $ret;
  305. }
  306. function get_next_obj_unlayed($src_table) {
  307. foreach($this->tables->$src_table->src_index as $obj) {
  308. if(!self::check_if_obj_is_layed($src_table,$obj)) {
  309. $ret[]=$obj;
  310. }
  311. }
  312. return $ret;
  313. }
  314. function lay_object($src_table,$obj,$start_x,$start_y) {
  315. $min_x=200;$min_y=0;
  316. //wykryj jakie X/Y jest aktualne
  317. //echo "\nvar ".$src_table."_".$obj." = new joint.shapes.basic.Rect({
  318. echo "\nvar ".$src_table."_".$obj." = new joint.shapes.devs.".self::get_type_table($src_table)."({
  319. position: { x: ".$this->tables->$src_table->obj_cursor[$obj]->x.", y: ".$this->tables->$src_table->obj_cursor[$obj]->y." },
  320. size: { width: ".self::get_obj_size_width($src_table,$obj).", height: ".self::get_obj_size_by_child_recurs($src_table,$obj)." }
  321. , attrs: {
  322. text: { text: '".self::get_obj_name($src_table,$obj).$obj."', fill: 'white' , 'y-alignment': 'top', 'x-alignment': 'left' } ,
  323. 'inPorts circle': { fill: 'PaleGreen' }
  324. } , label: { text: 'Dupa' }
  325. ".self::get_ports_for_obj($src_table,$obj)."
  326. });\n";
  327. self::notify_layed_object($src_table,$obj);
  328. self::lay_object_child($src_table,$obj);
  329. }
  330. function check_if_obj_is_layed($src_table,$obj) {
  331. return in_array($src_table."_".$obj, $this->cells);
  332. }
  333. function notify_layed_object($src_table,$obj) {
  334. $this->cells[]=$src_table."_".$obj;
  335. }
  336. function lay_object_child($src_table,$obj) {
  337. self::offset_layer_coords($src_table,5,0);
  338. foreach($this->tables->$src_table->childs[$obj]->tables as $child_table=>$child_table_arr) {
  339. foreach($child_table_arr as $child_id) {
  340. if($this->tables->$child_table->set_type_table=='Atomic') {
  341. self::calculate_obj_size_by_child_recurs($child_table,$child_id);
  342. self::set_obj_coords_by_parent($src_table,$obj,$child_table,$child_id);
  343. self::set_obj_size_width_by_parent($src_table,$obj,$child_table,$child_id,array('ratio'=>0.3) );
  344. self::lay_object($child_table,$child_id,$this->tables->$src_table->obj_cursor[$obj]->x,$this->tables->$src_table->obj_cursor[$obj]->y);
  345. } else if($this->tables->$child_table->set_type_table=='Ports') {
  346. // echo "\n //282 Trafilem na Ports";
  347. }
  348. }
  349. }
  350. }
  351. function get_ports_for_obj($src_table,$obj) {
  352. //do wykrycia portow dla tabeli typu
  353. echo "\n // 293 get_ports_for_obj".$src_table."/".$obj;
  354. if(isset($this->tables->$src_table->childs[$obj]->tables)) {
  355. foreach($this->tables->$src_table->childs[$obj]->tables as $child_tbl=>$child_id_arr) {
  356. if(self::get_type_table($child_tbl)=='Ports') {
  357. foreach($child_id_arr as $child_obj) {
  358. $ret[]=$child_tbl."_".$child_obj;
  359. $this->ports_obj[$child_tbl."_".$child_obj]=$src_table."_".$obj;
  360. $this->ports_tables[$child_tbl]=1;
  361. $this->ports_to_add_connect_link[]=array($child_tbl,$child_obj); //zapisanie do cache co ma sie wyzwolic potem
  362. //self::add_connect_links($child_tbl,$child_obj);
  363. }
  364. }
  365. }
  366. }
  367. if(!empty($ret)) {
  368. $ret=",outPorts: ['".implode("','", $ret)."']";
  369. return $ret;
  370. }
  371. }
  372. function add_connect_links($src_table,$obj) {
  373. echo "\n // 316 add_connect_links ".$src_table." / ".$obj;
  374. foreach($this->ports_tables as $port_table=>$val) {
  375. foreach($this->tables->$port_table->childs as $obj=>$val_) {
  376. foreach($this->tables->$port_table->childs[$obj]->tables as $child_table=>$child_table_arr) {
  377. foreach($child_table_arr as $child_obj) {
  378. // echo " i znalzalem ".$child_table." ".$child_obj;
  379. if(self::get_type_table($child_table)=='Connect') {
  380. if(count($this->tables->$child_table->parents->$port_table->tables[$child_obj]==2)) {
  381. // foreach($this->tables->$child_table->parents->$port_table->tables[$child_obj] as $link_id){
  382. // echo " (324) dodatk.".$link_id." ".$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][0];
  383. //jakia jest nazwa obiektu
  384. if(!empty($this->tables->$child_table->parents->$port_table->tables[$child_obj][1]))
  385. echo "\n connect(".$this->ports_obj[$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][0]].",'".$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][0]."',".$this->ports_obj[$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][1]].",'".$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][1]."'); ";
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. function joint_addCell_js() {
  394. $cells=implode(').addCell(', $this->cells);
  395. echo "\ngraph.addCell(".$cells.");\n";
  396. }
  397. function set_type_table($src_table,$type) {
  398. $this->tables->$src_table->set_type_table=$type;
  399. }
  400. function get_type_table($src_table) {
  401. return $this->tables->$src_table->set_type_table;
  402. }
  403. function DEBUG($src_table) {
  404. DEBUG_S(-3,$src_table,$this->tables->$src_table,__FILE__,__FUNCTION__,__LINE__);
  405. }
  406. function DEBUG_ports_obj() {
  407. DEBUG_S(-3,'DEBUG_ports_obj',$this->ports_obj,__FILE__,__FUNCTION__,__LINE__);
  408. DEBUG_S(-3,'DEBUG_ports_tables',$this->ports_tables,__FILE__,__FUNCTION__,__LINE__);
  409. DEBUG_S(-3,'ports_to_add_connect_link',$this->ports_to_add_connect_link,__FILE__,__FUNCTION__,__LINE__);
  410. }
  411. function to_html($src_table) {
  412. // DEBUG_S(-3,'Graph obj',$this->graph,__FILE__,__FUNCTION__,__LINE__);
  413. // DEBUG_S(-3,'tables',$this->tables,__FILE__,__FUNCTION__,__LINE__);
  414. ?>
  415. <link rel="stylesheet" href="stuff/joint-js/joint.css" />
  416. <div id="paper" class="paper"/></div>
  417. <script src="stuff/joint-js/joint.js"></script>
  418. <script src="stuff/joint-js/joint.shapes.devs.js"></script>
  419. <script>var graph = new joint.dia.Graph;
  420. var paper = new joint.dia.Paper({
  421. el: $('#paper'),
  422. width: 2800,
  423. height: 2600,
  424. gridSize: 1,
  425. model: graph
  426. });
  427. var connect = function(source, sourcePort, target, targetPort) {
  428. var link = new joint.shapes.devs.Link({
  429. source: { id: source.id, selector: source.getPortSelector(sourcePort) },
  430. target: { id: target.id, selector: target.getPortSelector(targetPort) }
  431. });
  432. graph.addCell(link);
  433. };
  434. <?
  435. //funkcja do znalezienia glownych obiektow, ktore maja byc narysowane obok siebie
  436. // idziemy od elementu o najmniejszej liczbie powiazan w prawo,
  437. // trzeceie powiazanie idzie pietro nizej (todo kiedy?)
  438. //function arrange_objects_layer($src_table,$minwidth=50,$minheight=100) {
  439. //1. poszukaj elementu z najmniejsza iloscia powiazan
  440. // $this->tables->$src_table->cursor->x=0;
  441. // $this->tables->$src_table->cursor->y=0;
  442. self::set_layer_coords($src_table,0,0);
  443. // self::get_next_obj($src_table,null,array('less_connections'));
  444. $situation=self::analyze_arrange_situation($src_table);
  445. // print_r($situation);
  446. while($obj=self::get_next_obj($src_table,$situation)) {
  447. echo "\n//631:: wzialem ID ".$obj;
  448. //foreach($this->tables->$src_table->src_index as $obj) {
  449. //DEBUG_S(-3,"Rysuje obiekt ".$src_table." o id ".$obj,null,__FILE__,__FUNCTION__,__LINE__);
  450. //self::add_obj()
  451. self::set_obj_coord_by_layer($src_table,$obj);
  452. self::calculate_obj_size_by_child_recurs($src_table,$obj);
  453. // self::set_obj_size_width($src_table,$obj,200);
  454. self::set_obj_size_width_by_min_y_size($src_table,$obj);
  455. // self::offset_layer_coords($src_table,0,0);
  456. self::lay_object($src_table,$obj);
  457. echo "\n //606: robie offset o ".self::get_obj_size_width($src_table,$obj)." dla obj ".$obj." bo x:".$this->tables->$src_table->obj_cursor[$obj]->x ." a width:".self::get_obj_size_width($src_table,$obj);
  458. self::offset_layer_coords($src_table,self::get_obj_size_width($src_table,$obj)+100,0);
  459. $situation=self::analyze_arrange_situation($src_table);
  460. }
  461. //malujemy teraz powiazania pomiedzy portami - nie mozna wczesniej, gdyz wszystkie obiekty musza sie pierw namalowac
  462. //foreach($this->ports_to_add_connect_link as $port_to_add_connect_link) {
  463. // self::add_connect_links($port_to_add_connect_link[0],$port_to_add_connect_link[1]);
  464. //}
  465. //}
  466. ?>
  467. var a1 = new joint.shapes.devs.Atomic({
  468. position: { x: 360, y: 360 },
  469. inPorts: ['port XY'],
  470. outPorts: ['x','y']
  471. });
  472. var a2 = new joint.shapes.devs.Atomic({
  473. position: { x: 50, y: 260 },
  474. outPorts: ['out']
  475. });
  476. var a3 = new joint.shapes.devs.Atomic({
  477. position: { x: 650, y: 150 },
  478. size: { width: 100, height: 300 },
  479. inPorts: ['a','b']
  480. });
  481. <?
  482. self::joint_addCell_js();
  483. self::add_connect_links();
  484. ?>
  485. // graph.addCell(opt_przelacznice_mufy_39).addCell(opt_przelacznice_mufy_38).addCell(opt_przelacznice_mufy_40);
  486. // a2.embed(a1);
  487. </script>
  488. <?
  489. }
  490. }
  491. function GIS_OPT_STRUCTURES2() {
  492. global $db,$gdb;
  493. $mysql_zas_id=36;
  494. $gis_zas_id=13102;
  495. $db = DB::getDB();
  496. $gdb= DB::getDB($gis_zas_id);
  497. DEBUG_S(-3,'db',$db);
  498. DEBUG_S(-3,'gis',$gdb);
  499. $cp=new GIS_OPT_STRUCTURES2;
  500. $cp->init();
  501. $cp->set_gis_zas_id($gis_zas_id);
  502. //$wezly=$cp->get_opt_objects('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje',"where \"Nazwa\" like '%test%'");
  503. $wezly=$cp->get_opt_objects('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje',"where \"id_0\" in(23,24,32,31,25,28,27) ");
  504. $cp->set_type_table('opt_przelacznice_mufy','Coupled');
  505. $tacki=$cp->get_opt_objects('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy');
  506. $cp->set_type_table('opt_tacki','Atomic');
  507. $spawy=$cp->get_opt_objects('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki');
  508. $cp->set_type_table('opt_spawy','Ports');
  509. $wlokna=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_a','opt_spawy');
  510. $cp->set_type_table('opt_wlokna','Connect');
  511. $wlokna2=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_b','opt_spawy');
  512. $spawy_b=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_b','id'); //chce znalezc te sprawy ktore sa w wloknach jako B
  513. $spawy_b2=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_a','id'); //chce znalezc te sprawy ktore sa w wloknach jako B
  514. $tacki_b=$cp->get_opt_objects_parent('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy','1=1','opt_spawy','id_tacka','id_0'); //chce znalezc te sprawy ktore sa w wloknach jako B
  515. $wezly_b=$cp->get_opt_objects_parent('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje','1=1','opt_tacki','id_przelac','id_0');
  516. // $cp->layer_arrange(1,array('opt_przelacznice_mufy'));
  517. /*
  518. $cp->add_array_to_graph($wezly,'PROCES_INIT');
  519. $cp->add_array_to_graph($tacki,null);
  520. $cp->add_array_to_graph($spawy,null);
  521. $cp->add_array_to_graph($wlokna,null);
  522. $cp->add_array_to_graph($wlokna2,null);
  523. $cp->add_array_to_graph($spawy_b,null);
  524. $cp->add_array_to_graph($spawy_b2,null);
  525. $cp->add_array_to_graph($tacki_b,null);
  526. $cp->add_array_to_graph($wezly_b,'PROCES_INIT');
  527. */
  528. $cp->find_connect_paths('opt_przelacznice_mufy');
  529. $cp->invert_layer_deepth();
  530. // $cp->arrange_objects_layer('opt_przelacznice_mufy');
  531. DEBUG_S(-3,'Wezly do dodania',$wezly,__FILE__,__FUNCTION__,__LINE__);
  532. DEBUG_S(-3,'tacki do dodania',$tacki,__FILE__,__FUNCTION__,__LINE__);
  533. $cp->to_html('opt_przelacznice_mufy');
  534. $cp->DEBUG('opt_przelacznice_mufy'); $cp->DEBUG('opt_spawy');
  535. $cp->DEBUG('opt_tacki');
  536. $cp->DEBUG('opt_spawy');
  537. $cp->DEBUG('opt_wlokna');
  538. $cp->DEBUG_ports_obj();
  539. // die();
  540. // foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, $graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null);
  541. // foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT');
  542. }
  543. ?>