Browse Source

NEW: SmartESL::SetPageImage
NEW: SmartESL::SwitchPage

Giancarlo Voci 7 years ago
parent
commit
6718b01563

+ 53 - 45
src/Modules/restful/restful.php

@@ -11,9 +11,11 @@ namespace Modules\restful;
 use Base;
 use Base;
 use OpenMind\FindBox\FindBoxCoreSystem;
 use OpenMind\FindBox\FindBoxCoreSystem;
 use OpenMind\FindBox\QueueCommand;
 use OpenMind\FindBox\QueueCommand;
+use OpenMind\FindBox\SmartESL;
 use OpenMind\System\GDSupport;
 use OpenMind\System\GDSupport;
 use OpenMind\System\PluginStrategy;
 use OpenMind\System\PluginStrategy;
 use OpenMind\System\QueueSystem;
 use OpenMind\System\QueueSystem;
+use Picqer\Barcode\BarcodeGeneratorPNG;
 use Template;
 use Template;
 
 
 define('API_VERSION', '1.10 beta test only');
 define('API_VERSION', '1.10 beta test only');
@@ -47,57 +49,63 @@ class restful extends PluginStrategy
 
 
 	public function RESTful_gentpl($f3)
 	public function RESTful_gentpl($f3)
 	{
 	{
-		$varCondizione = 0;
-
-		$grafica[] = ['BODY' => ['w' => 400, 'h' => 400]];
-		$grafica[] = ['FILL' => ['w' => 10, 'h' => 10, 'color' => '#0000FF']];
-		$grafica[] = ['TEXT' => [
-			'x' => '0',
-			'y' => '18',
-			'size' => 18,
-			'color' => $varCondizione == 1 ? '#FFFFFF' : '#00FF00',
-			'value' => 'ciao'
-		]];
-		$grafica[] = ['TEXT' => [
-			'x' => '0',
-			'y' => '37',
-			'size' => 12,
-			'color' => '#FF0000',
-			'value' => 'booohh'
-		]];
-
-		$grafica[] = ['RECTFILL' => [
-			'x1' => '20',
-			'y1' => '100',
-			'x2' => '120',
-			'y2' => '120',
-			'color' => '#FF0000',
+		$bolla = '01234567';
+		$bolla_filler = '1234567';
+		$lente_dx = 'ZSS 123456 DX';
+		$lente_sx = 'ZSS 123456 eee';
+		$lavorazione = 'COC';
+		$z_diametro_dx = '50';
+		$z_diametro_sx = '70';
+		$z_sfera_dx = '-0.75';
+		$z_sfera_sx = '-0.50';
+		$z_cilindro_dx = '+0.25';
+		$z_cilindro_sx = '+0.25';
+		$z_ubic_prod_dx = 'B-2-1';
+		$z_ubic_prod_sx = 'A-123-56';
+
+
+		$font = 'C:\Users\Giancarlo\AppData\Local\Microsoft\Windows\Fonts\Lato-Bold.ttf';
+		$fontBlack = 'C:\Users\Giancarlo\AppData\Local\Microsoft\Windows\Fonts\Lato-Black.ttf';
+		$fontSize = 15;
+
+		$grafica[] = ['BODY' => ['w' => 264, 'h' => 176, 'bgcolor' => '#FFFFFF']];
+
+		$grafica[] = ['LINE' => ['x1' => 0, 'y1' => 55, 'x2' => 263, 'y2' => 55, 'color' => '#000000']];
+		$grafica[] = ['LINE' => ['x1' => 0, 'y1' => 110, 'x2' => 263, 'y2' => 110, 'color' => '#000000']];
+
+		$grafica[] = ['TEXT' => ['x' => 10, 'y' => 22, 'size' => $fontSize, 'color' => '#000000', 'value' => $lente_dx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 10, 'y' => 47, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_diametro_dx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 45, 'y' => 47, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_sfera_dx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 100, 'y' => 47, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_cilindro_dx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 170, 'y' => 47, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_ubic_prod_dx, 'font' => $font]];
+
+		$grafica[] = ['TEXT' => ['x' => 10, 'y' => 77, 'size' => $fontSize, 'color' => '#000000', 'value' => $lente_sx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 10, 'y' => 102, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_diametro_sx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 45, 'y' => 102, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_sfera_sx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 100, 'y' => 102, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_cilindro_sx, 'font' => $font]];
+		$grafica[] = ['TEXT' => ['x' => 170, 'y' => 102, 'size' => $fontSize, 'color' => '#000000', 'value' => $z_ubic_prod_sx, 'font' => $font]];
+
+		$grafica[] = ['BARCODE' => [
+			'x' => 10, 'y' => 120,
+			'widthFactor' => 2,
+			'h' => 55,
+			'type' => BarcodeGeneratorPNG::TYPE_INTERLEAVED_2_5,
+			'value' => '01234567'
 		]];
 		]];
 
 
-		$grafica[] = ['LINE' => [
-			'x1' => '10',
-			'y1' => '10',
-			'x2' => '300',
-			'y2' => '300',
-			'color' => '#7A6E9C',
-		]];
 
 
-		$grafica[] = ['PIXEL' => [
-			'x' => '250',
-			'y' => '200',
-			'color' => '#0A9C05',
-		]];
+		$lavorazioneColor = $lavorazione == 'COC' ? '#FF0000' : '#000000';
+		$grafica[] = ['RECT' => ['x1' => 170, 'y1' => 120, 'x2' => 263, 'y2' => 175, 'color' => $lavorazioneColor, 'filled' => 1]];
 
 
-		$grafica[] = ['ELLIPSE' => [
-			'x' => '210',
-			'y' => '230',
-			'w' => '50',
-			'h' => '90',
-			'color' => '#9C5225',
-		]];
+		$grafica[] = ['TEXT' => ['x' => 178, 'y' => 161, 'size' => 26, 'color' => '#FFFFFF', 'value' => $lavorazione, 'font' => $fontBlack]];
 
 
 		$gd = new GDSupport();
 		$gd = new GDSupport();
-		$gd->Render($grafica, 'ciao.png');
+		$imageBin = $gd->Render($grafica);
+
+		$esl = new SmartESL($this->findBoxCore, ['01097D82']);
+		$esl->SetPageImage($imageBin, 2);
+		$esl->SwitchPage(2);
+
 	}
 	}
 
 
 	public function RESTful_ListAPIS($f3)
 	public function RESTful_ListAPIS($f3)

+ 9 - 1
src/OpenMind/FindBox/FindBoxCoreSystem.php

@@ -403,4 +403,12 @@ class FindBoxCoreSystem
 
 
 		$svgTemplate->save($svgPath);
 		$svgTemplate->save($svgPath);
 	}
 	}
-}
+
+	public function getJobStatus(array $id)
+	{
+		$ids = join(',', $id);
+		$URI = "/1.0.0/index.php/smartesl.getjobstatus/1.0.0/[[{$ids}]]";
+
+		return $this->CallAPI($URI, '');
+	}
+}

+ 42 - 0
src/OpenMind/FindBox/SmartESL.php

@@ -129,7 +129,49 @@ class SmartESL
 			1, 1));
 			1, 1));
 
 
 		return $this->core->CallAPI($URI, $params);
 		return $this->core->CallAPI($URI, $params);
+	}
+
+	/**
+	 * Set ESL display using displayimage CORE API
+	 *
+	 * @param string $binaryImage
+	 * @param int $pageNum
+	 * @return array
+	 */
+	public function SetPageImage(string $binaryImage, int $pageNum = 1)
+	{
+		$imageb64 = base64_encode($binaryImage);
+		$URI = "/1.0.0/index.php/smartesl.displayimage/1.1.1/";
+
+		$params = json_encode([array_map(function ($label) use ($pageNum, $imageb64) {
+			return [
+				'label_id' => $label,
+				'image' => $imageb64,
+				'page' => $pageNum
+			];
+		}, $this->labels)]);
 
 
+		return $this->core->CallAPI($URI, $params);
+	}
+
+	/**
+	 * Switch to ESL page $pageNum
+	 *
+	 * @param int $pageNum
+	 * @return array
+	 */
+	public function SwitchPage(int $pageNum = 1)
+	{
+		$URI = "/1.0.0/index.php/smartesl.switchpage/1.1.0/";
+
+		$params = json_encode([array_map(function ($label) use ($pageNum) {
+			return [
+				'label_id' => $label,
+				'page' => $pageNum
+			];
+		}, $this->labels)]);
+
+		return $this->core->CallAPI($URI, $params);
 	}
 	}
 
 
 	public function GetLabelMatch()
 	public function GetLabelMatch()

+ 48 - 18
src/OpenMind/System/GDSupport.php

@@ -7,6 +7,9 @@
 
 
 namespace OpenMind\System;
 namespace OpenMind\System;
 
 
+use Picqer\Barcode\BarcodeGeneratorPNG;
+use Picqer\Barcode\Exceptions\BarcodeException;
+
 /**
 /**
  * Class GDSupport
  * Class GDSupport
  * Facility for draw images using GD php library
  * Facility for draw images using GD php library
@@ -24,20 +27,11 @@ class GDSupport
 		$this->image = null;
 		$this->image = null;
 	}
 	}
 
 
-	/**
-	 * @param string $colorStr
-	 * @return false|int
-	 */
-	private function getColor(string $colorStr)
-	{
-		list($r, $g, $b) = sscanf($colorStr, "#%02x%02x%02x");
-		return imagecolorallocate($this->image, $r, $g, $b);
-	}
-
 	/**
 	/**
 	 * @param array $drawings
 	 * @param array $drawings
 	 * @param string|null $outputPathFile
 	 * @param string|null $outputPathFile
 	 * @return string if outputPathFile is null, return the image instead to write to file
 	 * @return string if outputPathFile is null, return the image instead to write to file
+	 * @throws BarcodeException
 	 */
 	 */
 	public function Render(array $drawings, $outputPathFile = NULL): string
 	public function Render(array $drawings, $outputPathFile = NULL): string
 	{
 	{
@@ -46,27 +40,53 @@ class GDSupport
 			$prop = $gdElement[$name];
 			$prop = $gdElement[$name];
 			$color = isset($prop['color']) ? $this->getColor($prop['color']) : NULL;
 			$color = isset($prop['color']) ? $this->getColor($prop['color']) : NULL;
 			switch ($name) {
 			switch ($name) {
+
 				case 'BODY':
 				case 'BODY':
 					$this->image = imagecreatetruecolor($prop['w'], $prop['h']);
 					$this->image = imagecreatetruecolor($prop['w'], $prop['h']);
+					imageantialias($this->image, true);
+					$bgColor = isset($prop['bgcolor']) ? $this->getColor($prop['bgcolor']) : NULL;
+					imagefill($this->image, 0, 0, $bgColor);
 					break;
 					break;
+
 				case 'TEXT':
 				case 'TEXT':
-					imagettftext($this->image, $prop['size'], 0, $prop['x'], $prop['y'], $color, 'C:\Windows\Fonts\arial.ttf', $prop['value']);
+					imagettftext($this->image, $prop['size'], 0, $prop['x'], $prop['y'], $color, $prop['font'], $prop['value']);
 					break;
 					break;
+
 				case 'FILL':
 				case 'FILL':
 					imagefill($this->image, $prop['x'], $prop['y'], $color);
 					imagefill($this->image, $prop['x'], $prop['y'], $color);
 					break;
 					break;
-				case 'RECTFILL':
-					imagefilledrectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
+
+				case 'RECT':
+					if (isset($prop['filled']))
+						imagefilledrectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
+					else
+						imagerectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
 					break;
 					break;
+
 				case 'LINE':
 				case 'LINE':
+					if (isset($prop['thickness']))
+						imagesetthickness($this->image, $prop['thickness']);
+
 					imageline($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
 					imageline($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
+
+					if (isset($prop['thickness']))  // Restore default tickness
+						imagesetthickness($this->image, 1);
 					break;
 					break;
+
 				case 'PIXEL':
 				case 'PIXEL':
 					imagesetpixel($this->image, $prop['x'], $prop['y'], $color);
 					imagesetpixel($this->image, $prop['x'], $prop['y'], $color);
 					break;
 					break;
+
 				case 'ELLIPSE':
 				case 'ELLIPSE':
 					imagefilledellipse($this->image, $prop['x'], $prop['y'], $prop['w'], $prop['h'], $color);
 					imagefilledellipse($this->image, $prop['x'], $prop['y'], $prop['w'], $prop['h'], $color);
 					break;
 					break;
+
+				case 'BARCODE':
+					$bcGen = new BarcodeGeneratorPNG();
+					$bcImg = $bcGen->getBarcode($prop['value'], $prop['type'], $prop['widthFactor'], $prop['h']);
+					$gdBcImg = imagecreatefromstring($bcImg);
+					imagecopy($this->image, $gdBcImg, $prop['x'], $prop['y'], 0, 0, imagesx($gdBcImg), imagesy($gdBcImg));
+					break;
 			}
 			}
 		}
 		}
 
 
@@ -77,16 +97,26 @@ class GDSupport
 		return $data;
 		return $data;
 	}
 	}
 
 
-	public function Destroy()
+	/**
+	 * @param string $colorStr
+	 * @return false|int
+	 */
+	private function getColor(string $colorStr)
 	{
 	{
-		if ($this->image) {
-			imagedestroy($this->image);
-			$this->image = NULL;
-		}
+		list($r, $g, $b) = sscanf($colorStr, "#%02x%02x%02x");
+		return imagecolorallocate($this->image, $r, $g, $b);
 	}
 	}
 
 
 	public function __destruct()
 	public function __destruct()
 	{
 	{
 		$this->Destroy();
 		$this->Destroy();
 	}
 	}
+
+	public function Destroy()
+	{
+		if ($this->image) {
+			imagedestroy($this->image);
+			$this->image = NULL;
+		}
+	}
 }
 }