00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 if ( !defined( 'MEDIAWIKI' ) ) {
00023 die( 'Not an entry point.' );
00024 }
00025
00046
00047
00048 $srfgPicturePath = "GraphViz/images/";
00049
00050
00051
00052 class SRFProcess extends SMWResultPrinter {
00053
00054
00055 protected $m_graphValidation = false;
00056 protected $m_isDebugSet = false;
00057 protected $m_processCategory = 'Process';
00058
00059
00060 protected $m_process;
00061
00066 protected function handleParameters( array $params, $outputmode ) {
00067 parent::handleParameters( $params, $outputmode );
00068
00069
00070 $this->m_process = new ProcessGraph();
00071
00072 $this->m_process->setGraphName( trim( $params['graphname'] ) );
00073 $this->m_process->setGraphSize( trim( $params['graphsize'] ) );
00074 $this->m_process->setClusterColor( trim( $params['clustercolor'] ) );
00075 $this->m_process->setRankdir( strtoupper( trim( $params['rankdir'] ) ) );
00076 $this->m_process->setHighlightNode( trim( $params['highlight'] ) );
00077 $this->m_process->setHighlightColor( trim( $params['highlightcolor'] ) );
00078 $this->m_process->setHighlightColor( trim( $params['redlinkcolor'] ) );
00079
00080 $this->m_process->setShowRoles( $params['showroles'] );
00081 $this->m_process->setShowStatus( $params['showstatus'] );
00082 $this->m_process->setShowRessources( $params['showresources'] );
00083 $this->m_process->setShowDiscussion( $params['showdiscussion'] );
00084 $this->m_process->setShowRedLinks( $params['showredlinks'] );
00085 $this->m_process->setShowCompound( $params['showcompound'] );
00086
00087 $this->m_processCategory = $params['processcat'];
00088 $this->m_isDebugSet = $params['debug'];
00089 $this->m_graphValidation = $params['graphvalidation'];
00090 }
00091
00098 public function getParameters() {
00099 $params = parent::getParameters();
00100
00101 $params['graphname'] = new Parameter( 'graphname', Parameter::TYPE_STRING, '' );
00102 $params['rankdir'] = new Parameter( 'rankdir', Parameter::TYPE_STRING, 'TB' );
00103 $params['graphsize'] = new Parameter( 'graphsize', Parameter::TYPE_STRING, '' );
00104 $params['clustercolor'] = new Parameter( 'clustercolor', Parameter::TYPE_STRING, 'lightgrey' );
00105 $params['highlight'] = new Parameter( 'highlight', Parameter::TYPE_STRING, '' );
00106 $params['highlightcolor'] = new Parameter( 'highlightcolor', Parameter::TYPE_STRING, 'blue' );
00107 $params['redlinkcolor'] = new Parameter( 'redlinkcolor', Parameter::TYPE_STRING, 'red' );
00108
00109 $params['showroles'] = new Parameter( 'showroles', Parameter::TYPE_BOOLEAN, false );
00110 $params['showstatus'] = new Parameter( 'showstatus', Parameter::TYPE_BOOLEAN, false );
00111 $params['showresources'] = new Parameter( 'showresources', Parameter::TYPE_BOOLEAN, false );
00112 $params['showdiscussion'] = new Parameter( 'showdiscussion', Parameter::TYPE_BOOLEAN, false );
00113 $params['showredlinks'] = new Parameter( 'showredlinks', Parameter::TYPE_BOOLEAN, false );
00114 $params['showcompound'] = new Parameter( 'showcompound', Parameter::TYPE_BOOLEAN, true );
00115
00116 $params['processcat'] = new Parameter( 'processcat', Parameter::TYPE_STRING, 'Process' );
00117 $params['debug'] = new Parameter( 'debug', Parameter::TYPE_BOOLEAN, false );
00118 $params['graphvalidation'] = new Parameter( 'graphvalidation', Parameter::TYPE_BOOLEAN, false );
00119
00120 return $params;
00121 }
00122
00131 protected function getResultText( SMWQueryResult $res, $outputmode ) {
00132 if ( !is_callable( 'renderGraphviz' ) ) {
00133 wfWarn( 'The SRF Graph printer needs the GraphViz extension to be installed.' );
00134 return '';
00135 }
00136
00137 global $wgContLang;
00138
00139
00140
00141
00142 global $wgGraphVizSettings;
00143 $this->isHTML = true;
00144
00145
00146
00147
00148
00149
00150 $row = $res->getNext();
00151
00152 while ( $row !== false ) {
00153 $subject = $row[0]->getResultSubject();
00154
00155 if ( $subject->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) {
00156 $wikiPageValue = new SMWWikiPageValue( '_wpg' );
00157 $wikiPageValue->setDataItem( $subject );
00158 $node = $this->m_process->makeNode( $wikiPageValue->getShortWikiText(), $wikiPageValue->getShortWikiText() );
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 foreach ( $row as $field ) {
00171
00172
00173 $req = $field->getPrintRequest();
00174 switch ( ( strtolower( $req->getLabel() ) ) ) {
00175
00176
00177
00178 case strtolower( $wgContLang->getNsText( NS_CATEGORY ) ):
00179
00180 foreach ( $field->getContent() as $value ) {
00181 $val = $value->getShortWikiText();
00182 if ( $val == ( $wgContLang->getNsText( NS_CATEGORY ) . ':' . $this->m_processCategory ) ) $node->setAtomic( false );
00183 }
00184
00185 break;
00186
00187 case "haslabel":
00188 $value = current($field->getContent());
00189 if (($value !== false)) {
00190 $val = $value->getLongWikiText();
00191 if ($this->m_process->getUseOtherLabels()) {
00192 $val = str_replace("&","and",$val);
00193 $node->setLabel($val);
00194 }
00195 }
00196 break;
00197
00198 case "hasrole":
00199 foreach ( $field->getContent() as $value ) {
00200 $val = $value->getShortWikiText();
00201 $role = $this->m_process->makeRole( $val, $val );
00202 $node->addRole( $role );
00203 }
00204 break;
00205
00206 case "usesresource":
00207 foreach ( $field->getContent() as $value ) {
00208 $val = $value->getShortWikiText();
00209 $xres = $this->m_process->makeRessource( $val, $val );
00210 $node->addUsedRessource( $xres );
00211 }
00212 break;
00213
00214 case "producesresource":
00215 foreach ( $field->getContent() as $value ) {
00216 $val = $value->getShortWikiText();
00217 $xres = $this->m_process->makeRessource( $val, $val );
00218 $node->addProducedRessource( $xres );
00219 }
00220 break;
00221
00222 case "hassuccessor":
00223
00224 if ( count( $field->getContent() ) > 1 ) {
00225
00226
00227 $edge = new SplitParallelEdge();
00228 $edge->setFrom( $node );
00229 foreach ( $field->getContent() as $value ) {
00230 $val = $value->getShortWikiText();
00231 $edge->addTo( $this->m_process->makeNode( $val, $val ) );
00232 }
00233
00234 } else {
00235
00236
00237 foreach ( $field->getContent() as $value ) {
00238 $val = $value->getShortWikiText();
00239 $edge = new SequentialEdge();
00240 $edge->setFrom( $node );
00241 $edge->setTo( $this->m_process->makeNode( $val, $val ) );
00242 }
00243 }
00244
00245 break;
00246
00247 case "hasorsuccessor":
00248
00249 if ( count( $field->getContent() ) > 0 ) {
00250
00251
00252 $edge = new SplitExclusiveOrEdge();
00253 $edge->setFrom( $node );
00254 foreach ( $field->getContent() as $value ) {
00255 $val = $value->getShortWikiText();
00256 $edge->addTo( $this->m_process->makeNode( $val, $val ) );
00257 }
00258 }
00259
00260 break;
00261
00262 case "hascontruesuccessor":
00263
00264 if ( count( $field->getContent() ) > 0 ) {
00265
00266
00267 if ( !isset( $cond_edge ) ) {
00268 $cond_edge = new SplitConditionalOrEdge();
00269 $cond_edge->setFrom( $node );
00270 }
00271
00272
00273 foreach ( $field->getContent() as $value ) {
00274 $val = $value->getShortWikiText();
00275 $cond_edge->setToTrue( $this->m_process->makeNode( $val, $val ) );
00276 }
00277
00278 }
00279
00280 break;
00281
00282 case "hasconfalsesuccessor":
00283
00284 if ( count( $field->getContent() ) > 0 ) {
00285
00286
00287 if ( !isset( $cond_edge ) ) {
00288 $cond_edge = new SplitConditionalOrEdge();
00289 $cond_edge->setFrom( $node );
00290 }
00291
00292
00293 foreach ( $field->getContent() as $value ) {
00294 $val = $value->getShortWikiText();
00295 $cond_edge->setToFalse( $this->m_process->makeNode( $val, $val ) );
00296 }
00297 }
00298
00299 break;
00300
00301 case "hascondition":
00302
00303 if ( count( $field->getContent() ) > 0 ) {
00304
00305
00306 if ( !isset( $cond_edge ) ) {
00307 $cond_edge = new SplitConditionalOrEdge();
00308 $cond_edge->setFrom( $node );
00309 }
00310
00311
00312 foreach ( $field->getContent() as $value ) {
00313 $val = $value->getShortWikiText();
00314 $cond_edge->setConditionText( $val );
00315
00316 }
00317 }
00318
00319 break;
00320
00321 case "hasstatus":
00322
00323
00324 foreach ( $field->getContent() as $value ) {
00325 $val = $value->getShortWikiText();
00326 $node->setStatus( $val );
00327 }
00328
00329 break;
00330
00331 default:
00332
00333
00334
00335 }
00336 }
00337
00338
00339 unset( $node );
00340 unset( $cond_edge );
00341
00342 $row = $res->getNext();
00343 }
00344
00345
00346
00347
00348 $graphInput = $this->m_process->getGraphVizCode();
00349
00350
00351
00352
00353 $result = renderGraphviz( $graphInput );
00354
00355 $debug = '';
00356 if ( $this->m_isDebugSet ) $debug = '<pre>' . $graphInput . '</pre>';
00357
00358 return $result . $debug;
00359 }
00360 }
00361
00365 class ProcessGraph {
00366
00367
00368 protected $m_graphName = '';
00369 protected $m_rankdir = 'TB';
00370 protected $m_graphSize = '';
00371 protected $m_clusterColor = 'lightgrey';
00372 protected $m_showStatus = false;
00373 protected $m_showRoles = false;
00374 protected $m_showRessources = false;
00375 protected $m_showDiscussion = false;
00376 protected $m_highlightNode = '';
00377 protected $m_highlightColor = 'blue';
00378 protected $m_showRedLinks = false;
00379 protected $m_redLinkColor = 'red';
00380 protected $m_showCompound = true;
00381
00382 public $m_useHtmlNodes = true;
00383
00384
00385 protected $m_nodes = array();
00386 protected $m_startnodes = array();
00387 protected $m_endnodes = array();
00388 protected $m_ressources = array();
00389 protected $m_roles = array();
00390 protected $m_errors = array();
00391
00392
00401 public function makeNode( $id, $label ) {
00402
00403 if ( isset( $this->m_nodes[$id] ) ) {
00404
00405 $node = $this->m_nodes[$id];
00406
00407 } else {
00408
00409
00410 $node = new ProcessNode();
00411 $node->setId( $id );
00412 $node->setLabel( $label );
00413 $node->setProcess( $this );
00414
00415
00416 if ( strcasecmp( $id , $this->m_highlightNode ) == 0 ) {
00417 $node->setFontColor( $this->m_highlightColor );
00418 }
00419
00420
00421 if ( $this->m_showRedLinks ) {
00422 $title = Title::newFromDBkey( $id );
00423 if ( isset( $title ) && ( !$title->exists() ) ) $node->setFontColor( $this->m_redLinkColor );
00424 }
00425
00426
00427 $this->m_nodes[$id] = $node;
00428 }
00429
00430 return $node;
00431
00432 }
00433
00434 public function makeRole( $id, $label ) {
00435
00436 if ( isset( $this->m_roles[$id] ) ) {
00437
00438 $role = $this->m_roles[$id];
00439
00440 } else {
00441 $role = new ProcessRole();
00442 $role->setId( $id );
00443 $role->setLabel( $label );
00444
00445
00446 $this->m_roles[$id] = $role;
00447 }
00448
00449 return $role;
00450
00451 }
00452
00453 public function makeRessource( $id, $label ) {
00454
00455 if ( isset( $this->m_ressources[$id] ) ) {
00456
00457 $res = $this->m_ressources[$id];
00458
00459 } else {
00460 $res = new ProcessRessource();
00461 $res->setId( $id );
00462 $res->setLabel( $label );
00463
00464
00465 $this->m_ressources[$id] = $res;
00466
00467 }
00468
00469 return $res;
00470
00471 }
00472
00473 public function getEndNodes() {
00474 if ( count( $this->m_endnodes ) == 0 ) {
00475 foreach ( $this->m_nodes as $node ) {
00476 if ( count( $node->getSucc() ) == 0 ) $this->m_endnodes[] = $node;
00477 }
00478 }
00479
00480 return $this->m_endnodes;
00481 }
00482
00483 public function getStartNodes() {
00484
00485 if ( count( $this->m_startnodes ) == 0 ) {
00486 foreach ( $this->m_nodes as $node ) {
00487 if ( count( $node->getPred() ) == 0 ) {
00488 $this->m_startnodes[] = $node;
00489 }
00490 }
00491 }
00492
00493 return $this->m_startnodes;
00494 }
00495
00496 public function setShowStatus( $show ) {
00497 $this->m_showStatus = $show;
00498 }
00499
00500 public function getShowStatus() {
00501 return $this->m_showStatus;
00502 }
00503
00504 public function setShowRoles( $show ) {
00505 $this->m_showRoles = $show;
00506 }
00507
00508 public function getShowRoles() {
00509 return $this->m_showRoles;
00510 }
00511
00512 public function setShowCompound( $show ) {
00513 $this->m_showCompound = $show;
00514 }
00515
00516 public function getShowCompound() {
00517 return $this->m_showCompound;
00518 }
00519
00520 public function setShowDiscussion($show){
00521 $this->m_showDiscussion = $show;
00522 }
00523
00524 public function getShowDiscussion(){
00525 return $this->m_showDiscussion;
00526 }
00527
00528 public function setShowRessources( $show ) {
00529 $this->m_showRessources = $show;
00530 }
00531
00532 public function getShowRessources() {
00533 return $this->m_showRessources;
00534 }
00535
00536 public function setGraphName( $name ) {
00537 $this->m_graphName = $name;
00538 }
00539
00540 public function getGraphName() {
00541 if ( $this->m_graphName == '' ) $this->m_graphName = 'ProcessQueryResult' . rand( 1, 99999 );
00542 return $this->m_graphName;
00543 }
00544
00545 public function setGraphSize( $size ) {
00546 $this->m_graphSize = $size;
00547 }
00548
00549 public function setRankdir( $rankdir ) {
00550 $this->m_rankdir = $rankdir;
00551 }
00552
00553 public function setClusterColor( $color ) {
00554 $this->m_clusterColor = $color;
00555 }
00556
00557 public function setHighlightColor( $color ) {
00558 $this->m_highlightColor = $color;
00559 }
00560
00561 public function setRedLinkColor( $color ) {
00562 $this->m_redLinkColor = $color;
00563 }
00564
00565 public function setShowRedLinks( $show ) {
00566 $this->m_showRedLinks = $show;
00567 }
00568
00569 public function setHighlightNode( $name ) {
00570 $this->m_highlightNode = $name;
00571 }
00572
00573 public function addError( $error ) {
00574 $this->m_errors[] = $error;
00575 }
00576
00577 public function getErrors() {
00578 return $this->m_errors;
00579 }
00580
00581 public function getGraphVizCode() {
00582
00583
00584
00585 $res = 'digraph ' . $this->getGraphName() . ' {
00586
00587 ranksep="0.5";';
00588 if ( $this->m_graphSize != '' ) $res .= '
00589 size="' . $this->m_graphSize . '";';
00590 $res .= '
00591 rankdir=' . $this->m_rankdir . ';
00592 ';
00593
00594
00595
00596
00597
00598 $res .= '
00599 {rank=source; "Start";}
00600 "Start"[shape=box,label="Start",style=filled,color=green];';
00601
00602 foreach ( $this->getStartNodes() as $node ) {
00603 $res .= '
00604 "Start" -> "' . $node->getId() .'":port1:n;';
00605 }
00606
00607 $res .= '
00608 ';
00609
00610
00611
00612
00613
00614 $res .= '
00615 {rank=sink; "End"; }
00616 "End"[shape=box,label="End",style=filled,color=green];';
00617
00618 foreach ( $this->getEndNodes() as $node ) {
00619 $res .= '
00620 "' . $node->getId() . '":port1:s -> "End";';
00621 }
00622
00623 $res .= '
00624
00625 ';
00626
00627
00628
00629
00630 foreach ( $this->m_nodes as $node ) {
00631 $res .= $node->getGraphVizCode();
00632 }
00633
00634
00635
00636
00637 $res .=
00638 '
00639 }';
00640
00641 return $res;
00642
00643 }
00644
00645 }
00646
00647 abstract class ProcessElement {
00648
00649
00650 private $m_id = 'no_id';
00651 private $m_label = 'unlabeled';
00652 private $m_uid;
00653
00654 public function getUUID(){
00655 if (!isset($this->m_uid)){
00656 $this->m_uid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
00657 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
00658 mt_rand(0, 0x0fff) | 0x4000,
00659 mt_rand(0, 0x3fff) | 0x8000,
00660 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
00661 }
00662
00663 return $this->m_uid;
00664 }
00665 public function getId() {
00666 return $this->m_id;
00667 }
00668
00669 public function setId( $id ) {
00670 $this->m_id = $id;
00671 }
00672
00673 public function getLabel() {
00674 return $this->m_label;
00675 }
00676
00677 public function setLabel( $label ) {
00678 $this->m_label = $label;
00679 }
00680
00681 }
00682
00683 class ProcessRessource extends ProcessElement {
00684
00685 private $m_usedby = array();
00686 private $m_producedby = array();
00687
00688 public function getProducers() {
00689 return $this->m_producedby;
00690 }
00691
00692 public function getUsers() {
00693 return $this->m_usedby;
00694 }
00695
00696 public function addProducer( $node ) {
00697 $this->m_producedby[] = $node;
00698 }
00699
00700 public function addUser( $node ) {
00701 $this->m_usedby[] = $node;
00702 }
00703
00704 }
00705
00706 class ProcessRole extends ProcessElement {
00707
00708 private $m_nodes = array();
00709
00710 public function getNodes() {
00711 return $this->m_nodes;
00712 }
00713
00714 public function addNode( $node ) {
00715 $this->m_nodes[] = $node;
00716 }
00717
00718 }
00719
00723 class ProcessNode extends ProcessElement {
00724
00725 private $m_is_startnode = false;
00726 private $m_is_endnode = false;
00727 private $m_status;
00728 private $m_is_atomic = true;
00729
00730 private $m_process;
00731
00732 private $m_fontColor = '';
00733
00734 private $m_usedressources = array();
00735 private $m_producedressources = array();
00736 private $m_roles = array();
00737
00738 private $m_edgeout;
00739 private $m_edgesin = array();
00740
00741 public function setStatus( $status ) {
00742 $this->m_status = $status;
00743 }
00744
00745 public function getStatus() {
00746 return $this->m_status;
00747 }
00748
00749 public function setFontColor( $color ) {
00750 $this->m_fontColor = $color;
00751 }
00752
00753 public function setProcess( $proc ) {
00754 $this->m_process = $proc;
00755 }
00756
00757 public function getProcess() {
00758 return $this->m_process;
00759 }
00760
00761 public function getPred() {
00762 $res = array();
00763
00764 foreach ( $this->m_edgesin as $edge ) {
00765 $res = array_merge( $res, $edge->getPred() );
00766 }
00767
00768 return $res;
00769 }
00770
00771 public function getSucc() {
00772 $res = array();
00773
00774 if ( isset( $this->m_edgeout ) ) {
00775 $res = $this->m_edgeout->getSucc();
00776 }
00777
00778 return $res;
00779 }
00780
00781 public function setEdgeOut( $edge ) {
00782 $this->m_edgeout = $edge;
00783 }
00784
00785 public function getEdgeOut() {
00786 return $this->m_edgeout;
00787 }
00788
00789 public function addEdgeIn( $edge ) {
00790 $this->m_edgesin[] = $edge;
00791 }
00792
00793 public function getEdgesIn() {
00794 return $this->m_edgesin;
00795 }
00796
00797 public function addRole( $role ) {
00798 $this->m_roles[] = $role;
00799 $role->addNode( $this );
00800 }
00801
00802 public function getRoles() {
00803 return $this->m_roles;
00804 }
00805
00806 public function addUsedRessource( $res ) {
00807 $this->m_usedressources[] = $res;
00808 $res->addUser( $this );
00809 }
00810
00811 public function getUsedRessources() {
00812 return $this->m_usedressources;
00813 }
00814
00815 public function addProducedRessource( $res ) {
00816 $this->m_producedressources[] = $res;
00817 $res->addProducer( $this );
00818 }
00819
00820 public function getProducedRessources() {
00821 return $this->m_producedressources;
00822 }
00823
00824 public function isAtomic() {
00825 return $this->m_is_atomic;
00826 }
00827
00828 public function setAtomic( $atomic ) {
00829 $this->m_is_atomic = $atomic;
00830 }
00831
00832 public function getGraphVizCode() {
00833 global $IP, $srfgPicturePath, $srfgIP;
00834
00835
00836
00837 $status = '';
00838 if ( $this->getProcess()->getShowStatus() ) {
00839
00840 if ( file_exists( $IP . "/images/p000.png" ) ) {
00841 $PicturePath = $IP . "/images/";
00842 } elseif ( file_exists( $srfgIP . "/GraphViz/images/p000.png" ) ) {
00843 $PicturePath = $srfgIP . "/GraphViz/images/";
00844 } else {
00845 $PicturePath = $IP . $srfgPicturePath;
00846 }
00847
00848
00849
00850 if ( $this->getStatus() != '' ) {
00851 if ( $this->getStatus() < 25 ) {
00852 $status = ' HREF="[[' . $this->getId() . ']]" TOOLTIP="status '.$this->getStatus().'%"><IMG SRC="' . $PicturePath .'p000.png" /';
00853 } elseif ( $this->getStatus() < 50 ) {
00854 $status = ' HREF="[[' . $this->getId() . ']]" TOOLTIP="status '.$this->getStatus().'%"><IMG SRC="' . $PicturePath .'p025.png" /';
00855 } elseif ( $this->getStatus() < 75 ) {
00856 $status = ' HREF="[[' . $this->getId() . ']]" TOOLTIP="status '.$this->getStatus().'%"><IMG SRC="' . $PicturePath .'p050.png" /';
00857 } elseif ( $this->getStatus() < 100 ) {
00858 $status = ' HREF="[[' . $this->getId() . ']]" TOOLTIP="status '.$this->getStatus().'%"><IMG SRC="' . $PicturePath .'p075.png" /';
00859 } elseif ( $this->getStatus() == 100 ) {
00860 $status = ' HREF="[[' . $this->getId() . ']]" TOOLTIP="status '.$this->getStatus().'%"><IMG SRC="' . $PicturePath .'p100.png" /';
00861 }
00862 }
00863
00864 }
00865
00866
00867
00868
00869 $discussion = '';
00870 if ( $this->getProcess()->getShowDiscussion() ) {
00871
00872 if ( file_exists( $IP . "/images/discuss_icon.png" ) ) {
00873 $PicturePath = $IP . "/images/";
00874 } elseif ( file_exists( $srfgIP . "/GraphViz/images/discuss_icon.png" ) ) {
00875 $PicturePath = $srfgIP . "/GraphViz/images/";
00876 } else {
00877 $PicturePath = $IP . $srfgPicturePath;
00878 }
00879 $discussionTitle = Title::newFromText('Talk:'.$this->getId().'');
00880 if ($discussionTitle->isKnown()) {
00881 $discussion = ' HREF="[[Talk:' . $this->getId() . ']]" TOOLTIP="Talk:' . $this->getId() . '"><IMG SRC="' . $PicturePath .'discuss_icon.png" /';
00882 } else {
00883 $discussion = ' HREF="[[Talk:' . $this->getId() . ']]" TOOLTIP="Talk:' . $this->getId() . '"><IMG SRC="' . $PicturePath .'discuss_icon_grey.png" /';
00884 }
00885
00886
00887 }
00888
00889
00890 $high = '';
00891 if ( $this->m_fontColor != '' ) {
00892 $high = ',fontcolor=' . $this->m_fontColor;
00893 }
00894
00895
00896 $compound = '<TR><TD ALIGN="LEFT" BORDER="0" WIDTH="20px">';
00897 if ($this->getProcess()->getShowCompound()){
00898 if ( file_exists( $IP . "/images/subprocess.png" ) ) {
00899 $PicturePath = $IP . "/images/";
00900 } elseif ( file_exists( $srfgIP . "/GraphViz/images/subprocess.png" ) ) {
00901 $PicturePath = $srfgIP . "/GraphViz/images/";
00902 } else {
00903 $PicturePath = $IP . $srfgPicturePath;
00904 }
00905 if (!$this->isAtomic()) $compound = '<TR><TD ALIGN="LEFT" BORDER="0" WIDTH="20px" HREF="[['. $this->getId() . ']]" TOOLTIP="sub process"><IMG SRC="' . $PicturePath .'subprocess.png"/>';
00906 }
00907
00908
00909
00910
00911
00912
00913 if ($this->m_process->m_useHtmlNodes){
00914 $res =
00915 '"' . $this->getId() . '" [shape=plaintext,label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">' . $compound . '</TD><TD BORDER="0" WIDTH="80%"></TD><TD ALIGN="RIGHT" BORDER="0" WIDTH="20px"' . $status . '></TD><TD ALIGN="RIGHT" BORDER="0" WIDTH="20px"' . $discussion . '></TD></TR><TR><TD COLSPAN="4" PORT="port1" HREF="[[' . $this->getId() . ']]" TOOLTIP="' . $this->getLabel() .'"><FONT' . $high .'>' . $this->getLabel() . '</FONT></TD> </TR></TABLE>>];
00916 ';
00917 } else {
00918 $res =
00919 '"' . $this->getId() . '"[label="' . $this->getLabel() . '",shape=rect, height=1.5, URL="[[' . $this->getId() . ']]"];
00920 ';
00921 }
00922
00923
00924
00925
00926 if ( isset( $this->m_edgeout ) ) $res .= $this->m_edgeout->getGraphVizCode();
00927
00928
00929
00930
00931
00932 $rrcluster = false;
00933 $rrcode = 'subgraph "cluster_role' . rand( 1, 9999 ) . '" { style=filled;color=lightgrey;';
00934
00935
00936 if ( $this->getProcess()->getShowRoles() ) {
00937
00938 foreach ( $this->getRoles() as $role ) {
00939 $rrcluster = true;
00940 $rrcode .= '
00941 "' . $role->getId() . '"[label="' . $role->getLabel() . '",shape=doubleoctagon, color=red, URL="[[' . $role->getId() . ']]"];
00942 "' . $role->getId() . '" -> "' . $this->getId() . '":port1 [color=red,arrowhead = none,constraint=false];
00943 ';
00944
00945 }
00946 }
00947
00948 if ( $this->getProcess()->getShowRessources() ) {
00949
00950 foreach ( $this->getUsedRessources() as $xres ) {
00951 $rrcluster = true;
00952 $rrcode .= '
00953 "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"];
00954 "' . $xres->getId() . '" -> "' . $this->getId() . '":port1 [color=blue,constraint=false];
00955 ';
00956 }
00957
00958 foreach ( $this->getProducedRessources() as $xres ) {
00959 $rrcluster = true;
00960 $rrcode .= '
00961 "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"];
00962 "' . $this->getId() . '":port1 -> "' . $xres->getId() . '" [color=blue,constraint=false];
00963 ';
00964 }
00965
00966 }
00967
00968 if ( $rrcluster ) $res .= $rrcode . '}';
00969
00970 $res .= '
00971 ';
00972
00973 return $res;
00974 }
00975
00976 }
00977
00978
00982 abstract class ProcessEdge{
00983
00984 private $m_id;
00985 private $m_uid;
00986
00987 public function getId(){
00988 if (!isset($this->m_id)){
00989 $this->m_id = 'edge' . rand(1, 99999);
00990 }
00991
00992 return $this->m_id;
00993 }
00994
00995 public function getUUID(){
00996 if (!isset($this->m_uid)){
00997 $this->m_uid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
00998 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
00999 mt_rand(0, 0x0fff) | 0x4000,
01000 mt_rand(0, 0x3fff) | 0x8000,
01001 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
01002 }
01003
01004 return $this->m_uid;
01005 }
01006
01007 abstract public function getSucc();
01008 abstract public function getPred();
01009
01010 abstract public function getGraphVizCode();
01011 }
01012
01013 abstract class SplitEdge extends ProcessEdge{
01014
01015 protected $m_from;
01016 protected $m_to = array();
01017
01018 public function setFrom($node){
01019 $this->m_from = $node;
01020 $node->setEdgeOut($this);
01021 }
01022
01023 public function addTo($node){
01024 $this->m_to[] = $node;
01025 $node->addEdgeIn($this);
01026 }
01027
01028 public function getPred(){
01029 return array($this->m_from);
01030 }
01031
01032 public function getSucc(){
01033 return $this->m_to;
01034 }
01035
01036 }
01037
01038 class SplitConditionalOrEdge extends ProcessEdge{
01039
01040 protected $m_from;
01041 protected $m_to_true;
01042 protected $m_to_false;
01043 protected $m_con_text = 'empty_condition';
01044
01045 public function getSucc(){
01046 return array($this->m_to_false, $this->m_to_true);
01047 }
01048
01049 public function getPred(){
01050 return array($this->m_from);
01051 }
01052
01053 public function setFrom($node){
01054 $this->m_from = $node;
01055 $node->setEdgeOut($this);
01056 }
01057
01058 public function setToFalse($node){
01059 $this->m_to_false = $node;
01060 $node->addEdgeIn($this);
01061 }
01062
01063 public function setToTrue($node){
01064 $this->m_to_true = $node;
01065 $node->addEdgeIn($this);
01066 }
01067
01068 public function setConditionText($cond){
01069 $this->m_con_text = $cond;
01070 }
01071
01072 public function getGraphVizCode(){
01073
01074 $p = $this->m_from;
01075
01076 if ((!isset($this->m_from)) || (!isset($this->m_to_false)) || (!isset($this->m_to_true))){
01077
01078 echo "error with SplitConditionalOrEdge";
01079 exit;
01080 }
01081
01082
01083 $res =
01084 'subgraph "clus_' . $this->getId() . '" {
01085 ';
01086
01087
01088 $con = 'con' . rand(1, 99999);
01089 $res .=
01090 '"'. $con . '"[shape=diamond,label="' . $this->m_con_text . '",style=filled,color=skyblue];
01091 "' . $p->getId() . '":port1:s -> "'. $con . '";
01092 ';
01093
01094
01095 $res .=
01096 '"' . $this->m_to_true->getId() . '" [URL = "[['. $this->m_to_true->getId() . ']]"];
01097 ';
01098
01099 $res .=
01100 '"'. $con .'" -> "' . $this->m_to_true->getId() .'":port1:n [label="true"];
01101 ';
01102
01103
01104 $res .=
01105 '"' . $this->m_to_false->getId() . '" [URL = "[['. $this->m_to_false->getId() . ']]"];
01106 ';
01107
01108 $res .=
01109 '"'. $con .'" -> "' . $this->m_to_false->getId() .'":port1:n [label="false"];';
01110
01111
01112 $res .= '
01113 }
01114 ';
01115
01116 return $res;
01117 }
01118
01119 }
01120
01121 class SplitExclusiveOrEdge extends SplitEdge{
01122
01123 public function getGraphVizCode(){
01124 global $srfgShapeStyle;
01125 $p = $this->getPred();
01126 $p = $p[0];
01127 if ($srfgShapeStyle=='') $srfgShapeStyle="box";
01128 $res =
01129 'subgraph "clus_' . $this->getId() . '" {
01130 ';
01131
01132
01133 $orx = 'or' . rand(1, 99999);
01134 $res .=
01135 '"'. $orx . '"[shape=' . $srfgShapeStyle . ',label="+",style=filled,color=gold];
01136 "' . $p->getId() . '":port1:s -> "'. $orx . '";
01137 ';
01138
01139 foreach ($this->getSucc() as $s){
01140 $res .=
01141 '"' . $s->getId() . '" [URL="[['. $s->getId() . ']]"];
01142 ';
01143
01144 $res .=
01145 '"'. $orx .'" -> "' . $s->getId() .'":port1:n;
01146 ';
01147 }
01148
01149 $res .= '
01150 }
01151 ';
01152
01153 return $res;
01154 }
01155
01156 }
01157
01158 class SplitParallelEdge extends SplitEdge{
01159
01160
01161 public function getGraphVizCode(){
01162 global $srfgShapeStyle;
01163 if ($srfgShapeStyle=='') $srfgShapeStyle="box";
01164 $p = $this->getPred();
01165 $p = $p[0];
01166
01167 $res =
01168 'subgraph "clus_' . $this->getId() . '" {
01169 ';
01170
01171
01172 $and = 'and' . rand(1, 99999);
01173 $res .=
01174 '"'. $and . '"[shape=' . $srfgShapeStyle . ',label="||",style=filled,color=palegreen];
01175 "' . $p->getId() . '":port1:s -> "'. $and . '";
01176 ';
01177
01178 foreach ($this->getSucc() as $s){
01179 $res .=
01180 '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"];
01181 ';
01182
01183 $res .=
01184 '"'. $and .'" -> "' . $s->getId() .'":port1:n;
01185 ';
01186 }
01187
01188 $res .= '
01189 }
01190 ';
01191
01192 return $res;
01193 }
01194
01195 }
01196
01197 class SequentialEdge extends ProcessEdge{
01198
01199 private $m_from;
01200 private $m_to;
01201
01202 public function setFrom($node){
01203 $this->m_from = $node;
01204 $node->setEdgeOut($this);
01205 }
01206
01207 public function setTo($node){
01208 $this->m_to = $node;
01209 $node->addEdgeIn($this);
01210 }
01211
01212 public function getPred(){
01213 return array($this->m_from);
01214 }
01215
01216 public function getSucc(){
01217 return array($this->m_to);
01218 }
01219
01220 public function getGraphVizCode(){
01221
01222 $p = $this->m_from;
01223 $s = $this->m_to;
01224
01225 $res =
01226 'subgraph "clus_' . $this->getId() . '" {
01227 ';
01228
01229 $res .=
01230 '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"];
01231 ';
01232
01233 $res .=
01234 '"'. $p->getId() .'":port1:s -> "' . $s->getId() .'":port1:n;';
01235
01236 $res .= '
01237 }
01238 ';
01239
01240 return $res;
01241 }
01242
01243 }