| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924 |
- <?php
- //
- // synchronizacja do serwera postgres GIS
- //
- include_once('se-lib/DB_Dump.php');
- include_once('se-lib/UsersHelper.php');
- Lib::Loadclass('Nodes_path_analys');
- class GIS_OPT_STRUCTURES2 {
- function __construct() {
- $this->width=800;
-
- }
- function init() {
-
- $this->graph = new stdClass();
- $this->graph->htmlID = 'graph_proces_id_' . $id_proces;
- $this->graph->procesTreeFlat = array();
- $this->graph->procesTreeGoto = array();
- $this->graph->treeItems = array();
- $this->graph->elements = new stdClass();
- $this->graph->elements->nodes = array();
- $this->graph->elements->edges = array();
-
- }
- function set_mysql_zas_id($mysql_zas_id) {
- $this->mysql_zas_id=$mysql_zas_id;
- }
- function set_gis_zas_id($gis_zas_id) {
- $this->gis_zas_id=$gis_zas_id;
- $this->gdb=DB::getDB($this->gis_zas_id);
- }
-
-
- 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) {
-
-
- $sql='select \''.$src_table.'\' as src_table , "'.$src_index.'" as src_index ';
- if(!empty($src_name)) $sql.=', "'.$src_name.'" as src_name ';
- $sql.=', "'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" '.$limit.' ;';
- $res=$this->gdb->query($sql);
- while($h=$this->gdb->fetch($res)) {
- if(!empty($limit)) {
- //bierzemy wszystkie rekordy bo byl limit
- $arr[]=$h;
- $this->tables->$src_table->src_index[]=$h->src_index;
- $this->tables->$src_table->data[$h->src_index]=$h;
-
- } else {
- //tylko te rekordy dla ktorych byly powiazania
- if(in_array($h->parent_table_id, $this->tables->$parent_table->src_index)) {
- $this->tables->$src_table->src_index[]=$h->src_index;
- // echo "<br> <font color=green>id ".$h->parent_table_id." IS found in ".$parent_table." parent table</font>";
- $arr[]=$h;
- $this->tables->$src_table->data[$h->src_index]=$h;
- // $this->tables->$src_table->childs[$h->src_index]=array();
-
- if(!in_array($h->src_index, $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table])) {
- $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
- $this->tables->$parent_table->childs[$h->parent_table_id]->objects[]=$src_table."_".$h->src_index;
-
- $this->tables->$parent_table->child_recurs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
- // echo "<br> Table to ".$src_table." a parent to ".$parent_table;
- }
-
- } //else echo "<br> id ".$h->parent_table_id." not found in ".$parent_table." parent table";
- }
-
- }
- return $arr;
-
- }
-
-
- 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){
- $i=0;
- $where_in=implode(",", $this->tables->$child_table->src_index);
-
- $sql='select \''.$src_table.'\' as src_table , t1."'.$src_index.'" as src_index ';
- if(!empty($src_name)) $sql.=', t1."'.$src_name.'" as src_name ';
- $sql.=', t1."'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" as t1
- inner join "'.$child_table.'" as t2 on t1."'.$src_index.'"=t2."'.$child_joinfield.'"
- where t2."'.$child_index.'" in ('.$where_in.') ;';
-
- // echo "<br> sql: ".$sql;
- $res=$this->gdb->query($sql);
- while($h=$this->gdb->fetch($res)) {
- $i++;
- // if($i>5) continue;
- if(!in_array($h->src_index, $this->tables->$src_table->src_index)) {
- $this->tables->$src_table->src_index[]=$h->src_index;
- $this->tables->$src_table->data[$h->src_index]=$h;
- $arr[]=$h;
- }
- if($h->parent_table_id)
- if(!in_array($h->src_index, $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table])) {
- $this->tables->$parent_table->childs[$h->parent_table_id]->tables[$src_table][]=$h->src_index;
- $this->tables->$parent_table->childs[$h->parent_table_id]->objects[]=$src_table."_".$h->src_index;
- }
- // echo "<br> (".$src_table.") child_joinfield is ".$child_joinfield." from ".$parent_table." val is ".$h->parent_table_id;
- }
- return $arr;
-
- }
-
- function set_layer_deepth($src_table,$deepth) {
- $this->tables->$src_table->deepth=$deepth;
- }
-
- function get_layer_deepth($src_table) {
- return $this->tables->$src_table->deepth;
- }
-
- function invert_layer_deepth() {
- $deepth=0;
- foreach($this->tables as $src_table=>$obj_data) {
- if($obj_data->deepth>$deepth) $deepth=$obj_data->deepth;
- }
-
- foreach($this->tables as $src_table=>$obj_data) {
- $this->tables->$src_table->deepth=$deepth-$this->tables->$src_table->deepth;
- //echo "<br>182 Deepht".$deepth." w ".$src_table;
- }
- }
-
-
- //rekursywne nadanie wszystkim obiektom powiazan/sciezek, aby mozna bylo je przesortowac i poukladac po kolei - aby obiekty root znaly swoje powiazania
- function find_connect_paths($src_table,$deepth=0) {
- self::set_layer_deepth($src_table,$deepth);
- $deepth++;
- //najpierw zjezdzamy w dol po dzieciach dajac znac na sam dol o ID nadrzenego
- //echo "<hr> odpalam funkcje path dla ".$src_table;
- //for($i = 1; $i <= 10; $i++) {
- foreach($this->tables->$src_table->childs as $id_parent=>$child) {
- // echo "<br> Szumam dzieci..";
- foreach($child->tables as $table=>$child_) {
- foreach($child_ as $id ) {
- // echo "<br> Wpisalem do dziecka ".$table." , ze parent is ".$id_parent." /".$child_;echo " = ".$id;
- $this->tables->$table->parents->$src_table->tables[$id][]=$id_parent;
- if(!in_array($table, $tables_to_connect)) $tables_to_connect[]=$table;
- }
- }
- foreach($this->tables->$src_table->parents as $parent_table=>$parent_data) {
- //echo "<br> 140: parent_table= ".$parent_table;
-
- foreach($parent_data->tables as $src_id=>$parents) {
- // echo " 142: (".$src_id.")";
- foreach($parents as $dst_id) {
- foreach($this->tables->$src_table->childs[$src_id]->tables as $child_table=>$child_id_arr) {
- foreach($child_id_arr as $child_id) {
-
- // 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;
- self::notify_child_node_about_parents($child_table,$parent_table,$child_id,$dst_id);
- self::add_link_from_recurse_struct($child_table,$parent_table,$child_id);
- $this->tables->$parent_table->child_recurs[$dst_id]->tables[$child_table][$child_id]=1;
- // $this->tables->$parent_table->size[$dst_id]->all++;
- }
- }
- //$this->tables->$src_table->parents->$parent_table->tables[$id][]=$id_parent;
- }
- }
- }
- }
-
- // }
- //potem patrzymy czy wystepuje jakis obiekt naszego typu w dol, jezeli tak, to zapisujemy to , ze ma polaczenie przez obiekty podrzedne
- foreach($tables_to_connect as $table) {
- self::find_connect_paths($table,$deepth);
- }
-
- }
-
-
- //funkcja informuje dzieci obiektu o tym, jakich ma rodzicow
- function notify_child_node_about_parents($child_table,$parent_table,$child_id,$dst_id) {
- if(!in_array($dst_id, $this->tables->$child_table->parents->$parent_table->tables[$child_id])) {
- //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__);
- $this->tables->$child_table->parents->$parent_table->tables[$child_id][]=$dst_id;
- }
- }
-
-
- //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
- function add_link_from_recurse_struct($child_table,$parent_table,$child_id) {
- if(count($this->tables->$child_table->parents->$parent_table->tables[$child_id])>1) {
- 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__);
- $first=false;
- foreach($this->tables->$child_table->parents->$parent_table->tables[$child_id] as $link) {
- if(!$first) $first=$link;
- else {
- $this->tables->$parent_table->links->$first->$link=true;
- $this->tables->$parent_table->links->$link->$first=true;
- }
- }
-
- }
-
- }
-
- function set_layer_coords($src_table,$start_x,$start_y) {
- $this->tables->$src_table->cursor->x=$start_x;
- $this->tables->$src_table->cursor->y=$start_y;
- }
-
- function offset_layer_coords($src_table,$x,$y) {
- $this->tables->$src_table->cursor->x+=$x;
- $this->tables->$src_table->cursor->y+=$y;
- }
-
- function set_obj_coord_by_layer($src_table,$obj) {
- $this->tables->$src_table->obj_cursor[$obj]->x=$this->tables->$src_table->cursor->x;
- $this->tables->$src_table->obj_cursor[$obj]->y=$this->tables->$src_table->cursor->y;
- }
- function get_obj_cursor_layer($src_table,$obj,$xy) {
- return $this->tables->$src_table->obj_cursor[$obj]->$xy;
- }
-
- function set_obj_size_width($src_table,$obj,$width) {
- $this->tables->$src_table->obj_width[$obj]=$width+20;
- }
-
-
- function set_obj_min_y_size($src_table,$obj,$size) {
- $this->tables->$src_table->min_y_size[$obj]=$size;
- }
-
- function set_obj_size_width_by_min_y_size($src_table,$obj) {
- self::set_obj_size_width($src_table,$obj,$this->tables->$src_table->min_x_size[$obj]);
- }
-
-
- function set_obj_size_width_by_parent($parent_table,$parent_obj,$src_table,$obj,$opts) {
- if(isset($opts['ratio']))
- $this->tables->$src_table->obj_width[$obj]=$this->tables->$parent_table->obj_width[$parent_obj]*$opts['ratio'];
- }
-
- function get_obj_size_width($src_table,$obj) {
- return $this->tables->$src_table->obj_width[$obj];
- }
-
-
-
- function set_obj_coords_by_parent($parent_table,$parent_obj,$src_table,$obj) {
- echo "\n// set_obj_coords_by_parent (".$parent_table.",".$parent_obj.",".$src_table.",".$obj.") ";
- $this->tables->$src_table->obj_cursor[$obj]->x=$this->tables->$parent_table->obj_cursor[$parent_obj]->x+10;
- $this->tables->$src_table->obj_cursor[$obj]->y=$this->tables->$parent_table->obj_cursor[$parent_obj]->y+15;
- echo " - i setted ".$this->tables->$parent_table->obj_cursor[$parent_obj]->x."/ ".$this->tables->$parent_table->obj_cursor[$parent_obj]->y;
- }
-
-
-
- function calculate_obj_size_by_child_recurs($src_table,$obj) {
- $count=0;$width=0;
- echo "\n//Licze size dla ".$src_table.' / '.$obj;
- foreach($this->tables->$src_table->child_recurs[$obj]->tables as $child_table=>$child_table_arr) {
- if(self::get_type_table($child_table)=='Connect') continue;
- echo " - ".$child_table;
- $count+=count($child_table_arr)*20;
- 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
- }
- $count_local=count($this->tables->$src_table->childs[$obj]->objects)*20;
-
- if($width<100) $width=100;
- if($count_local>$count) $count=$count_local;
- $count=$count+15+self::get_layer_deepth($src_table)*20;
- // $this->tables->$src_table->min_y_size[$obj]=$count;
-
- self::set_obj_min_y_size($src_table,$obj,$count);
- $this->tables->$src_table->min_x_size[$obj]=$width;
-
- }
-
- function get_obj_size_by_child_recurs($src_table,$obj) {
- echo "\n // get_obj_size_by_child_recurs dla ".$src_table." wynosi ".$obj." = ".$this->tables->$src_table->min_y_size[$obj];
- return $this->tables->$src_table->min_y_size[$obj];
-
- }
-
- function get_obj_name($src_table,$obj) {
- return $this->tables->$src_table->data[$obj]->src_name;
- }
-
-
- //funkcja do zwracania pierwszego obiektu wg roznych kryteriow : najmniej_powiazan, powiazanie z poprzednim, etc...
- function get_next_obj($src_table,$situation) {
- echo "\n /* 313: Situation <-- for ".$src_table;
- print_r($situation);
- print_r($this->get_next_obj);
- echo "*/\n";
-
- $ret=self::get_next_obj_by_path($src_table);
- if(!empty($ret)) { $this->get_next_obj->last_obj=$ret; return $ret; }
- //die('327 Skonczyla sie nowa sciezka uzyc/przeliczyc!');
-
-
- echo "\n //322 Skonczyla sie sciezka, nowa przeliczamy";
- self::analyze_arrange_paths($src_table,self::get_next_obj_unlayed($src_table));
- self::make_offset_layer_coords_by_fit_new_path($src_table);
- $ret=self::get_next_obj_by_path($src_table);
- if(!empty($ret)) {
- $this->get_next_obj->last_obj=$ret;
- if(!empty($ret)) return $ret;
- }
-
-
-
- if($situation->count>1) {
- if($situation->min_links==0) $ret=$situation->min_links_id;
- else if($situation->min_links==1) { echo "\n// 320:Sytuacja min_links==1";
- //bierzemy pod uwage rozmieszczenie sciezek - sprobujemy analizowac tylko te, ktore sa wyswietlone
-
- if(isset($this->get_next_obj->last_obj)) {
- if(isset($this->get_next_obj->last_obj_count)) {
-
- echo "\n //324::szukamy kogos, do kogo mamy podpiecie ";
- $var=$this->get_next_obj->last_obj;
- foreach(self::get_next_obj_unlayed($src_table) as $obj) {
- if(isset($this->tables->$src_table->links->$obj->$var))
- if(in_array($obj, $situation->min_links_id_arr))
- $ret=$obj;
- }
- } else {
- //poprzedni nie mial zadnego powiazania
- $ret=$situation->min_links_id;
- }
- }
- }
- } else $ret=$situation->id;
-
- $this->get_next_obj->last_obj=$ret;
-
-
-
-
- if(!isset($ret)) $ret=$situation->id;
-
- return $ret;
-
- }
-
-
- function analyze_arrange_paths($src_table,$unlayed) {
- //do szukania najdluzszej sciezki
- echo "\n /* 370 f.analyze_arrange_paths unlayed";
- print_r($unlayed);
- echo "*/";
- $w = new Nodes_path_analys;
- $sciezki=$w->trasuj_wezly($this->tables->$src_table->links,$unlayed);
- $najdluzsza=$w->najdluzsza_sciezka();
- $this->tables->$src_table->Nodes_path_analys->paths=$sciezki;
- $this->tables->$src_table->Nodes_path_analys->longest=$najdluzsza;
- //print_r($sciezki);
- }
-
-
- function make_offset_layer_coords_by_fit_new_path($src_table) {
- //przyklad
- //stara sceizka 41,23,24,31
- //nowa sciezka 25,28,27,32,29,30
- //wezel 25 ma powiazanie z 24, zatem sciezka nowa powinna wystartowac pod namalowanym wezlem 24
- //offset_layer_coords(,,)
- echo "\n /* 392: tables->".$src_table.">layed ";
- print_r($this->tables->$src_table->layed);
- //print_r($this->tables->$src_table->obj_cursor);
- //szukam do ktorego moge sie przylozyc wezla na podstawie sciezki
- $najdluzsza=$this->tables->$src_table->Nodes_path_analys->longest;
- foreach($this->tables->$src_table->Nodes_path_analys->paths[$najdluzsza] as $wezel) {
- // echo " 402: sprawdzam:".$wezel;
- foreach($this->tables->$src_table->links->$wezel as $link=>$link_) {
- // echo " sprawdzam:".$link;
- if(isset($this->tables->$src_table->layed[$link])) {
- 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...
- $height=self::get_obj_size_by_child_recurs($src_table,$wezel);
- 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." ";
- $this->tables->$src_table->layed[$link]->start_y=+$height;
- 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);
- //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);
- print_r($this->tables->$src_table->layed);
- echo "*/";
- return ;
- }
- }
- echo " 402:".$wezel;
- }
- echo "najdluzsza:".$najdluzsza." */";
-
-
- }
-
-
- function get_next_obj_by_path($src_table) {
- //proba skorzystania z pierwszej sciezki
- $longest=$this->tables->$src_table->Nodes_path_analys->longest;
- foreach($this->tables->$src_table->Nodes_path_analys->paths[$longest] as $ret) {
- foreach(self::get_next_obj_unlayed($src_table) as $obj) {
- echo "\n //322: get_next_obj_unlayed testuje ".$obj." dla ".$src_table;
- if($obj==$ret) {
- echo "\n //327: zwracam ze sciezki ".$ret;
- return $ret;
- }
- }
-
- }
- }
-
-
- function analyze_arrange_situation($src_table) {
- $var=$this->get_next_obj->last_obj;
- if(isset($this->get_next_obj->last_obj)) {
- if(isset($this->tables->$src_table->links->$var)) {
- echo "\n // 354: analyze_arrange_situation dla ".$this->get_next_obj->last_obj." ";
- $co=0;
- foreach($this->tables->$src_table->links->$var as $cos=>$cos_) {
- $co++;
- }
- $this->get_next_obj->last_obj_count=$co;
- } else echo "\n //353: no exists links for ".$var;
- }
- $max_links=0;
-
-
- foreach(self::get_next_obj_unlayed($src_table) as $obj) {
- $cnt[]=$obj;
- echo "\n //334: max_links=".$max_links." id ".$max_links_id." min is ".$min_links." id is ".$min_links_id." obj[".$obj."]";
- $count=0;
- if(isset($this->tables->$src_table->links->$obj)) {
-
- foreach($this->tables->$src_table->links->$obj as $link) {
- $count++;
- }
- }
- echo "\n// 315:jeszcze nie pojawil sie ".$src_table." [".$obj."] count: ".$count;
- if(isset($max_links)) {
- if($count>$max_links) {
- $max_links=$count;
- $max_links_id=$obj;
- unset($max_links_id_arr);
- $max_links_id_arr[]=$obj;
- } else if($count==$max_links) $max_links_id_arr[]=$obj;
- }
- if(isset($min_links)) {
- if($count<$min_links) {
- $min_links=$count;
- $min_links_id=$obj;
- unset($min_links_id_arr);
- $min_links_id_arr[]=$obj;
- } else if($count==$min_links) $min_links_id_arr[]=$obj;
- }
-
-
- if(!isset($min_links)) {
- $min_links=$count;$min_links_id=$obj;$min_links_id_arr[]=$obj;
- }
- if(!isset($max_links)) {
- $max_links=$count;$max_links_id=$obj;$max_links_id_arr[]=$obj;
- }
-
- }
-
- $ret->min_links=$min_links;
- $ret->max_links=$max_links;
- $ret->min_links_id=$min_links_id;
- $ret->max_links_id=$max_links_id;
- $ret->max_links_id_arr=$max_links_id_arr;
- $ret->min_links_id_arr=$min_links_id_arr;
- $ret->count=count($cnt);
- $ret->id=$cnt[0];
-
- echo "\n/* Analiza wezlow do rozmieszczenia" ; print_r($ret); echo "*/\n";
- return $ret;
-
-
-
-
- }
-
-
-
-
- function get_next_obj_unlayed($src_table) {
- foreach($this->tables->$src_table->src_index as $obj) {
- if(!self::check_if_obj_is_layed($src_table,$obj)) {
- $ret[]=$obj;
- }
- }
- return $ret;
-
- }
-
- function lay_object($src_table,$obj,$start_x,$start_y) {
-
- $min_x=200;$min_y=0;
- //wykryj jakie X/Y jest aktualne
-
-
- //echo "\nvar ".$src_table."_".$obj." = new joint.shapes.basic.Rect({
- $height=self::get_obj_size_by_child_recurs($src_table,$obj);
- $width=self::get_obj_size_width($src_table,$obj);
- echo "\nvar ".$src_table."_".$obj." = new joint.shapes.devs.".self::get_type_table($src_table)."({
-
- position: { x: ".self::get_obj_cursor_layer($src_table,$obj,'x').", y: ".self::get_obj_cursor_layer($src_table,$obj,'y')." },
- size: { width: ".$width.", height: ".$height." }
- , attrs: {
- text: { text: '".self::get_obj_name($src_table,$obj).$obj."', fill: 'black' , 'y-alignment': 'top', 'x-alignment': 'left' } ,
- 'inPorts circle': { fill: 'PaleGreen' }
- } , label: { text: 'Dupa' }
- ".self::get_ports_for_obj($src_table,$obj)."
- });\n";
- 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);
- self::lay_object_child($src_table,$obj);
- }
-
- function check_if_obj_is_layed($src_table,$obj) {
- return in_array($src_table."_".$obj, $this->cells);
- }
-
- function notify_layed_object($src_table,$obj,$start_x,$start_y,$height,$width) {
- $this->cells[]=$src_table."_".$obj;
- if(isset($this->paper_used)) {
- if($this->paper_used->y<$start_y+$height) $this->paper_used->y=$start_y+$height;
- } else $this->paper_used->y=$start_y+$height;
- self::notify_layed_obj_xyh($src_table,$obj,$start_x,$start_y,$height);
- }
-
- function notify_lay_nextrow() {
- if(isset($this->paper_used->rows)) $this->paper_used->rows++;
- else $this->paper_used->rows=1;
- return $this->paper_used->rows;
-
- }
-
- function notify_layed_obj_xyh($src_table,$obj,$start_x,$start_y,$height=null) {
- $this->tables->$src_table->layed[$obj]->start_x=$start_x;
- $this->tables->$src_table->layed[$obj]->start_y=$start_y;
- if(isset($height)) $this->tables->$src_table->layed[$obj]->height=$height;
- }
-
- function lay_object_child($src_table,$obj) {
- self::offset_layer_coords($src_table,5,0);
- foreach($this->tables->$src_table->childs[$obj]->tables as $child_table=>$child_table_arr) {
- foreach($child_table_arr as $child_id) {
- if($this->tables->$child_table->set_type_table=='Atomic') {
- self::calculate_obj_size_by_child_recurs($child_table,$child_id);
- self::set_obj_coords_by_parent($src_table,$obj,$child_table,$child_id);
- self::set_obj_size_width_by_parent($src_table,$obj,$child_table,$child_id,array('ratio'=>0.3) );
- self::lay_object($child_table,$child_id);
- } else if($this->tables->$child_table->set_type_table=='Ports') {
- // echo "\n //282 Trafilem na Ports";
- }
- }
-
- }
-
- }
-
- function get_ports_for_obj($src_table,$obj) {
- //do wykrycia portow dla tabeli typu
- echo "\n // 293 get_ports_for_obj".$src_table."/".$obj;
- if(isset($this->tables->$src_table->childs[$obj]->tables)) {
- foreach($this->tables->$src_table->childs[$obj]->tables as $child_tbl=>$child_id_arr) {
-
- if(self::get_type_table($child_tbl)=='Ports') {
- foreach($child_id_arr as $child_obj) {
- $ret[]=$child_tbl."_".$child_obj;
- $this->ports_obj[$child_tbl."_".$child_obj]=$src_table."_".$obj;
- $this->ports_tables[$child_tbl]=1;
- $this->ports_to_add_connect_link[]=array($child_tbl,$child_obj); //zapisanie do cache co ma sie wyzwolic potem
- //self::add_connect_links($child_tbl,$child_obj);
- }
-
- }
- }
- }
- if(!empty($ret)) {
- $ret=",outPorts: ['".implode("','", $ret)."']";
- return $ret;
- }
- }
-
-
-
- function add_connect_links($src_table,$obj) {
- echo "\n // 316 add_connect_links ".$src_table." / ".$obj;
- foreach($this->ports_tables as $port_table=>$val) {
- foreach($this->tables->$port_table->childs as $obj=>$val_) {
- foreach($this->tables->$port_table->childs[$obj]->tables as $child_table=>$child_table_arr) {
- foreach($child_table_arr as $child_obj) {
- // echo " i znalzalem ".$child_table." ".$child_obj;
- if(self::get_type_table($child_table)=='Connect') {
-
-
- if(count($this->tables->$child_table->parents->$port_table->tables[$child_obj]==2)) {
- // foreach($this->tables->$child_table->parents->$port_table->tables[$child_obj] as $link_id){
- // echo " (324) dodatk.".$link_id." ".$port_table."_".$this->tables->$child_table->parents->$port_table->tables[$child_obj][0];
- //jakia jest nazwa obiektu
- if(!empty($this->tables->$child_table->parents->$port_table->tables[$child_obj][1]))
- 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]."'); ";
- }
-
- }
- }
- }
- }
-
- }
-
- }
-
- function joint_addCell_js() {
- $cells=implode(').addCell(', $this->cells);
- echo "\ngraph.addCell(".$cells.");\n";
- }
-
-
-
-
-
- function set_type_table($src_table,$type) {
- $this->tables->$src_table->set_type_table=$type;
- }
-
- function get_type_table($src_table) {
- return $this->tables->$src_table->set_type_table;
- }
- function DEBUG($src_table) {
-
- DEBUG_S(-3,$src_table,$this->tables->$src_table,__FILE__,__FUNCTION__,__LINE__);
-
- }
-
- function DEBUG_ports_obj() {
-
- DEBUG_S(-3,'DEBUG_ports_obj',$this->ports_obj,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'DEBUG_ports_tables',$this->ports_tables,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'ports_to_add_connect_link',$this->ports_to_add_connect_link,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'opt_przelacznice_mufy->links',$this->tables->opt_przelacznice_mufy->links,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'opt_lokalizacje->links',$this->tables->opt_lokalizacje->links,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'opt_przelacznice_mufy->Nodes_path_analys',$this->tables->opt_przelacznice_mufy->Nodes_path_analys,__FILE__,__FUNCTION__,__LINE__);
- }
-
- function to_html($src_table) {
-
-
-
- // DEBUG_S(-3,'Graph obj',$this->graph,__FILE__,__FUNCTION__,__LINE__);
- // DEBUG_S(-3,'tables',$this->tables,__FILE__,__FUNCTION__,__LINE__);
- ?>
- <link rel="stylesheet" href="stuff/joint-js/joint.css" />
- <div id="paper" class="paper"/></div>
- <script src="stuff/joint-js/joint.js"></script>
- <script src="stuff/joint-js/joint.shapes.devs.js"></script>
- <script>var graph = new joint.dia.Graph;
- var paper = new joint.dia.Paper({
- el: $('#paper'),
- width: 2800,
- height: 2600,
- gridSize: 1,
- model: graph
- });
- var connect = function(source, sourcePort, target, targetPort) {
- var link = new joint.shapes.devs.Link({
- source: { id: source.id, selector: source.getPortSelector(sourcePort) },
- target: { id: target.id, selector: target.getPortSelector(targetPort) }
- });
- graph.addCell(link);
- };
- <?
-
- //funkcja do znalezienia glownych obiektow, ktore maja byc narysowane obok siebie
- // idziemy od elementu o najmniejszej liczbie powiazan w prawo,
- // trzeceie powiazanie idzie pietro nizej (todo kiedy?)
- //function arrange_objects_layer($src_table,$minwidth=50,$minheight=100) {
- //1. poszukaj elementu z najmniejsza iloscia powiazan
- // $this->tables->$src_table->cursor->x=0;
- // $this->tables->$src_table->cursor->y=0;
- self::set_layer_coords($src_table,0,0);
- // self::get_next_obj($src_table,null,array('less_connections'));
- $situation=self::analyze_arrange_situation($src_table);
-
- while($obj=self::get_next_obj($src_table,$situation)) {
-
- echo "\n//631:: wzialem ID ".$obj;
- //foreach($this->tables->$src_table->src_index as $obj) {
-
- //DEBUG_S(-3,"Rysuje obiekt ".$src_table." o id ".$obj,null,__FILE__,__FUNCTION__,__LINE__);
- //self::add_obj()
-
- self::set_obj_coord_by_layer($src_table,$obj);
- self::calculate_obj_size_by_child_recurs($src_table,$obj);
- // self::set_obj_size_width($src_table,$obj,200);
- self::set_obj_size_width_by_min_y_size($src_table,$obj);
- // self::offset_layer_coords($src_table,0,0);
- self::lay_object($src_table,$obj);
- 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);
- self::offset_layer_coords($src_table,self::get_obj_size_width($src_table,$obj)+150,0);
- $situation=self::analyze_arrange_situation($src_table);
- }
-
- //malujemy teraz powiazania pomiedzy portami - nie mozna wczesniej, gdyz wszystkie obiekty musza sie pierw namalowac
- //foreach($this->ports_to_add_connect_link as $port_to_add_connect_link) {
- // self::add_connect_links($port_to_add_connect_link[0],$port_to_add_connect_link[1]);
- //}
- //}
-
- ?>
- var a1 = new joint.shapes.devs.Atomic({
- position: { x: 360, y: 360 },
- inPorts: ['port XY'],
- outPorts: ['x','y']
- });
- var a2 = new joint.shapes.devs.Atomic({
- position: { x: 50, y: 260 },
- outPorts: ['out']
- });
- var a3 = new joint.shapes.devs.Atomic({
- position: { x: 650, y: 150 },
- size: { width: 100, height: 300 },
- inPorts: ['a','b']
- });
- <?
- self::joint_addCell_js();
- self::add_connect_links();
- ?>
- // graph.addCell(opt_przelacznice_mufy_39).addCell(opt_przelacznice_mufy_38).addCell(opt_przelacznice_mufy_40);
- // a2.embed(a1);
- </script>
- <?
-
-
- }
-
-
-
-
-
- }
- function GIS_OPT_STRUCTURES2() {
- global $db,$gdb;
- $mysql_zas_id=36;
- $gis_zas_id=13102;
-
-
-
- $db = DB::getDB();
- $gdb= DB::getDB($gis_zas_id);
-
-
- DEBUG_S(-3,'db',$db);
- DEBUG_S(-3,'gis',$gdb);
-
- $cp=new GIS_OPT_STRUCTURES2;
- $cp->init();
- $cp->set_gis_zas_id($gis_zas_id);
-
-
- //$wezly=$cp->get_opt_objects('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje',"where \"Nazwa\" like '%test%'");
- $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) ");
- $cp->set_type_table('opt_przelacznice_mufy','Coupled');
- $tacki=$cp->get_opt_objects('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy');
- $cp->set_type_table('opt_tacki','Atomic');
- $spawy=$cp->get_opt_objects('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki');
- $cp->set_type_table('opt_spawy','Ports');
- $wlokna=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_a','opt_spawy');
- $cp->set_type_table('opt_wlokna','Connect');
- $wlokna2=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_b','opt_spawy');
-
- $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
- $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
- $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
- $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');
- // $cp->layer_arrange(1,array('opt_przelacznice_mufy'));
-
-
- /*
- $cp->add_array_to_graph($wezly,'PROCES_INIT');
- $cp->add_array_to_graph($tacki,null);
- $cp->add_array_to_graph($spawy,null);
- $cp->add_array_to_graph($wlokna,null);
- $cp->add_array_to_graph($wlokna2,null);
- $cp->add_array_to_graph($spawy_b,null);
- $cp->add_array_to_graph($spawy_b2,null);
- $cp->add_array_to_graph($tacki_b,null);
- $cp->add_array_to_graph($wezly_b,'PROCES_INIT');
- */
- $cp->find_connect_paths('opt_lokalizacje');
- echo "<pre>";
- $cp->analyze_arrange_paths('opt_przelacznice_mufy'); //analizuje jakie sa sciezki glowne i ustalam dla nich rozmieszczenie
- echo "</pre>";
- // $cp->find_connect_paths('opt_przelacznice_mufy');
- $cp->invert_layer_deepth();
- // $cp->arrange_objects_layer('opt_przelacznice_mufy');
- DEBUG_S(-3,'Wezly do dodania',$wezly,__FILE__,__FUNCTION__,__LINE__);
- DEBUG_S(-3,'tacki do dodania',$tacki,__FILE__,__FUNCTION__,__LINE__);
- $cp->to_html('opt_przelacznice_mufy');
-
- $cp->DEBUG('opt_lokalizacje');
- $cp->DEBUG('opt_przelacznice_mufy'); $cp->DEBUG('opt_spawy');
- $cp->DEBUG('opt_tacki');
- $cp->DEBUG('opt_spawy');
- $cp->DEBUG('opt_wlokna');
- $cp->DEBUG_ports_obj();
- // die();
-
- // foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, $graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null);
- // foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT');
-
-
-
- }
-
-
-
-
-
-
-
-
-
- ?>
|