superedit-GIS_OPT_STRUCTURES2.php 31 KB

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