Commit fb7f73aab9ec59435bfd57f8181504228d319d4d

Authored by Benjamin Renard
1 parent 18e507a3

Fix expression parser for 2D parameters (fix for #6755)

Showing 1 changed file with 29 additions and 11 deletions   Show diff stats
src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php
... ... @@ -85,6 +85,7 @@ class IHMExpressionParserClass
85 85 "2/abs(1+dst)" => array("expression" => "2/(abs(1+\$dst))", "params" => array(array("paramid" => "dst"))),
86 86 "cross(vect_1,vect_2)" => array("expression" => "(cross(\$vect_1,\$vect_2))", "params" => array(array("paramid" => "vect_1"), array("paramid" => "vect_2"))),
87 87 "cross(cross(vect_1,vect_2),vect_3)" => array("expression" => "(cross((cross(\$vect_1,\$vect_2)),\$vect_3))","params" => array(array("paramid" => "vect_1"), array("paramid" => "vect_2"), array("paramid" => "vect_3"))),
  88 + "c1_hia_pad(0,0)/c1_hia_pad(0,1)" => array ("expression" => "\$c1_hia_pad[0][0]/\$c1_hia_pad[0][1]", "params" => array(array("paramid" => "c1_hia_pad"))),
88 89 );
89 90  
90 91 //init constants, aliases and functions for test
... ... @@ -633,11 +634,12 @@ class IHMExpressionParserClass
633 634 */
634 635 private function addParameterComponentInParameterArray($paramId, $component, &$params)
635 636 {
636   - foreach ($params as &$param)
637   - if ($param["id"] == $paramId)
638   - {
639   - array_push($param["indexes"],$component);
640   - return;
  637 + foreach ($params as &$param) {
  638 + if ($param["id"] == $paramId)
  639 + {
  640 + array_push($param["indexes"],$component);
  641 + return;
  642 + }
641 643 }
642 644 }
643 645  
... ... @@ -694,8 +696,16 @@ class IHMExpressionParserClass
694 696 $this->addParameterIdInParameterArray($param,$params);
695 697 if ($this->isParameterComponent($tree,$i+1))
696 698 {
697   - $this->addParameterComponentInParameterArray($param, $tree[$i+1][0], $params);
698   - $param .= ("[".$tree[$i+1][0]."]");
  699 + if ((count($tree[$i+1]) == 3) && ($tree[$i+1][1] == ',') && $this->isInteger($tree[$i+1][2])) {
  700 + //2D
  701 + $this->addParameterComponentInParameterArray($param, array($tree[$i+1][0], $tree[$i+1][2]), $params);
  702 + $param .= ("[".$tree[$i+1][0]."][".$tree[$i+1][2]."]");
  703 + }
  704 + else {
  705 + //1D
  706 + $this->addParameterComponentInParameterArray($param, $tree[$i+1][0], $params);
  707 + $param .= ("[".$tree[$i+1][0]."]");
  708 + }
699 709 ++$i;
700 710 }
701 711 }
... ... @@ -835,7 +845,7 @@ class IHMExpressionParserClass
835 845  
836 846 for ($i = 0; $i < count($tree); ++$i)
837 847 {
838   - //echo "=> ".$tree[$i].PHP_EOL;
  848 + #echo "=> ".$tree[$i].PHP_EOL;
839 849 if (is_array($tree[$i]))
840 850 {
841 851 //echo "ARRAY".PHP_EOL;
... ... @@ -879,7 +889,7 @@ class IHMExpressionParserClass
879 889 $founded = false;
880 890 foreach ($params as $param)
881 891 {
882   - //echo "TEST ".$param["id"].PHP_EOL;
  892 + #echo "TEST ".$param["id"].PHP_EOL;
883 893  
884 894 if (array_key_exists("template_args", $param))
885 895 {
... ... @@ -897,8 +907,15 @@ class IHMExpressionParserClass
897 907 foreach ($param["indexes"] as $index)
898 908 {
899 909 $temp = "";
900   - $temp .= ($param["id"]."[".$index."]");
901   - //echo "TEST 2 ".$temp.PHP_EOL;
  910 + if (is_array($index) && (count($index) == 2)) {
  911 + //2D
  912 + $temp .= ($param["id"]."[".$index[0]."][".$index[1]."]");
  913 + }
  914 + else {
  915 + //1D
  916 + $temp .= ($param["id"]."[".$index."]");
  917 + }
  918 + #echo "TEST 2 ".$temp.PHP_EOL;
902 919 if ($temp == $tree[$i])
903 920 {
904 921 $founded = true;
... ... @@ -906,6 +923,7 @@ class IHMExpressionParserClass
906 923 break;
907 924 }
908 925 }
  926 +
909 927 if ($founded)
910 928 break;
911 929 }
... ...