X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Fclass_BaseSimulator.php;h=d26ea246fe2ed5e23f4165ff880bc52155a4f801;hp=4726d299649a89ea2c9a049517a819d5fca149dd;hb=b3d612dc053c999af135677df431f73d9d26154f;hpb=ff66822b5fb6a92f5dc8af55290ecb89ec7f1aaf diff --git a/application/ship-simu/main/class_BaseSimulator.php b/application/ship-simu/main/class_BaseSimulator.php index 4726d29..d26ea24 100644 --- a/application/ship-simu/main/class_BaseSimulator.php +++ b/application/ship-simu/main/class_BaseSimulator.php @@ -1,6 +1,26 @@ + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ class BaseSimulator extends BaseFrameworkSystem { // Schiffsteilinstanz private $partInstance = null; @@ -22,103 +42,53 @@ class BaseSimulator extends BaseFrameworkSystem { ); // Konstruktor - private function __construct ($class) { + protected function __construct ($className) { // Call highest constructor - parent::constructor($class); - - if ((defined('DEBUG_CORE')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.
\n", - $this->__toString() - )); - - // Set part description and class name - $this->setPartDescr("Simulator-Basis-Einheit"); + parent::__construct($className); - // Etwas aufraeumen, dies sollte ganz zum Schluss erfolgen! + // Clean up a little, dies sollte ganz zum Schluss erfolgen! $this->removeResizeFactorArray(); $this->removeCurrPart(); $this->removeCurrShip(); } - // Public constructor - public function constructor ($class) { - // Call real constructor - $this->__construct($class); - } - - // Magic __isset method - private function __isset ($var) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Checking %s in class.
\n", - $this->__toString(), $var - )); - return isset($this->$var); - } - - // Magic __unset method - private function __unset($var) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Removing %s from class.
\n", - $this->__toString(), $var - )); - unset($this->$var); - } - // Setter-Methode fuer Laenge - public function setLength ($length) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] %dm Länge gesetzt.
\n", - $this->__toString(), - $length - )); + public final function setLength ($length) { $this->length = (float) $length; } // Setter-Methode fuer Breite - public function setWidth ($width) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] %dm Breite gesetzt.
\n", - $this->__toString(), - $width - )); + public final function setWidth ($width) { $this->width = (float) $width; } // Setter-Methode fuer Hoehe - public function setHeight ($height) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] %dm Höhe gesetzt.
\n", - $this->__toString(), - $height - )); + public final function setHeight ($height) { $this->height = (float) $height; } // Getter-Methode fuer Laenge - public function getLength () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Länge angefordert.
\n", - $this->__toString() - )); + public final function getLength () { return $this->length; } // Getter-Methode fuer Breite - public function getWidth () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Länge angefordert.
\n", - $this->__toString() - )); + public final function getWidth () { return $this->width; } // Getter-Methode fuer Hoehe - public function getHeight () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Höhe angefordert.
\n", - $this->__toString() - )); + public final function getHeight () { return $this->height; } // Setter-Methode fuer Teil-Instanz - public function setPartInstance ($struct) { - $this->partInstance = (Object) $struct; + public final function setPartInstance (ConstructableShipPart $partInstance) { + $this->partInstance = $partInstance; } // Getter-Methode fuer Teil-Instanz - public function getPartInstance () { + public final function getPartInstance () { if (!isset($this->partInstance)) { return null; } @@ -126,19 +96,8 @@ class BaseSimulator extends BaseFrameworkSystem { } // Remover-Methode fuer die Teil-Instanz - public function removePartInstance () { - if ($this->getPartInstance() !== null) { - // Warnung ausgeben - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] partInstance ist nicht null! Instanz-Attribut wird nicht entfernt.
\n", - $this->__toString() - )); - } else { - // Leere Instanz kann entfernt werden - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] partInstance wurde entfernt.
\n", - $this->__toString() - )); - unset($this->partInstance); - } + public final function removePartInstance () { + unset($this->partInstance); } // Prueft ob all Umberechnungsfaktoren gesetzt sind @@ -155,37 +114,18 @@ class BaseSimulator extends BaseFrameworkSystem { $this->currShip = $shipInstance; $this->currPart = $partInstance; - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Maschinenraum mit Motor %s wird fuer das Schiff %s konstruiert.
\n", - $this->__toString(), - $this->currPart->getPartDescr(), - $this->currShip->getShipName() - )); - // Passt ueberhaupt das Schiffsteil in's Schiff? if ($this->isShipPartSizeValid()) { - // Berechnungen fuer umliegendes Objekt anpassen - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Das Schiffsteil %s vom Typ %s passt in das Schiff %s hinein.
\n", - $this->__toString(), - $this->currPart->getPartDescr(), - $this->currPart->__toString(), - $this->currShip->getShipName() - )); - // Muessen die Masse angepasst werden? if ($this->isResizeFactorValid()) { // Neue Angaben berechnen (wir lassen etwas Lust fuer Kabelbaeume, Roehren, Maschinisten, etc.) - $this->newWidth = (float) $this->currPart->getWidth() * $this->resizeFactorArray['width']; - $this->newHeight = (float) $this->currPart->getHeight() * $this->resizeFactorArray['height']; - $this->newLength = (float) $this->currPart->getLength() * $this->resizeFactorArray['length']; + $this->newWidth = (float) $this->getCurrPart()->getWidth() * $this->resizeFactorArray['width']; + $this->newHeight = (float) $this->getCurrPart()->getHeight() * $this->resizeFactorArray['height']; + $this->newLength = (float) $this->getCurrPart()->getLength() * $this->resizeFactorArray['length']; // Passt dies nun immer noch? if ($this->isNewSizeValid()) { // Das passt auch, dann Werte setzen und Motor-Instanz merken - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Das Schiffsteil %s passt in das Schiff %s hinein.
\n", - $this->__toString(), - $this->getPartDescr(), - $this->currShip->getShipName() - )); $this->setWidth($this->newWidth); $this->setHeight($this->newHeight); $this->setLength($this->newLength); @@ -195,173 +135,139 @@ class BaseSimulator extends BaseFrameworkSystem { } else { // Passt nicht! Also wieder Exception werfen... throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil %s vom Typ %s ist zu gross für das Schiff!", - $this->currPart->__toString(), - $this->currPart->getPartDescr(), - $this->currPart->__toString() + $this->getCurrPart()->__toString(), + $this->getCurrPart()->getObjectDescription(), + $this->getCurrPart()->__toString() ), 2); } } elseif ($this->currPart != null) { // Aktuelle Masse setzen - $this->setWidth($this->currPart->getWidth()); - $this->setHeight($this->currPart->getHeight()); - $this->setLength($this->currPart->getLength()); + $this->setWidth($this->getCurrPart()->getWidth()); + $this->setHeight($this->getCurrPart()->getHeight()); + $this->setLength($this->getCurrPart()->getLength()); } // Existiert ein Schiffsteil? if (!is_null($this->currPart)) { - // Debug-Meldung ausgeben - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Schiffsteil %s gefunden.
\n", - $this->currPart->realClass, - $this->currPart->getPartDescr() - )); - // Schiffsteil-Instanz setzen $this->setPartInstance($this->currPart); // Instanzen entfernen - $this->currPart->removeCurrShip(); - $this->currPart->removeCurrPart(); - $this->currPart->removePartInstance(); - $this->currPart->removeResizeFactorArray(); + $this->getCurrPart()->removeCurrShip(); + $this->getCurrPart()->removeCurrPart(); + $this->getCurrPart()->removePartInstance(); + $this->getCurrPart()->removeResizeFactorArray(); } } else { // Exception werfen! throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil %s vom Typ %s passt nicht in das Schiff!", - $this->currPart->realClass, - $this->currPart->getPartDescr(), - $this->currPart->__toString() + $this->getCurrPart()->realClass, + $this->getCurrPart()->getObjectDescription(), + $this->getCurrPart()->__toString() ), 1); } - // Nochmals etwas aufraeumen + // Nochmals Clean up a little $this->removeResizeFactorArray(); $this->removeCurrShip(); $this->removeCurrPart(); } // Array fuer Umrechnungstabelle entfernen - public function removeResizeFactorArray () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeResizeFactor erreicht.
\n", - $this->__toString() - )); + public final function removeResizeFactorArray () { unset($this->resizeFactorArray); } - // Alle newXXX-Attribute entfernen - public function removeAllNewAttr () { + /** + * Remove all new*** attributes + * + * @return void + */ + public final function removeAllNewAttr () { unset($this->newWidth); unset($this->newHeight); unset($this->newLength); } - // Aktuelle Schiff-Instanz entfernen - public function removeCurrShip () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeCurrShip erreicht.
\n", - $this->__toString() - )); + /** + * Remove current ship instance + * + * @return void + */ + public final function removeCurrShip () { unset($this->currShip); } - // Aktuelle Schiff-Instanz entfernen - public function removeCurrPart () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeCurrPart erreicht.
\n", - $this->__toString() - )); + // Aktuelle Schiffsteil-Instanz entfernen + public final function removeCurrPart () { unset($this->currPart); } // Breite entfernen - public function removeWidth () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Breite entfernt.
\n", - $this->__toString() - )); + public final function removeWidth () { unset($this->width); } // Hoehe entfernen - public function removeHeight () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Höhe entfernt.
\n", - $this->__toString() - )); + public final function removeHeight () { unset($this->height); } // Laenge entfernen - public function removeLength () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Länge entfernt.
\n", - $this->__toString() - )); + public final function removeLength () { unset($this->length); } // Tiefgang entfernen - public function removeDraught () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Tiefgang entfernt.
\n", - $this->__toString() - )); + public final function removeDraught () { unset($this->draught); } // Getter-Methode fuer Element aus resizeFactor - public function getResizeFactorElement ($el) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] getResizeFactorElement erreicht. (element=%s)
\n", - $this->__toString(), - $el - )); + public final function getResizeFactorElement ($el) { if (isset($this->resizeFactorArray[$el])) { // Element gefunden return $this->resizeFactorArray[$el]; } else { // Element nicht gefunden! - return 0; + return null; } } // Setter-Methode fuer Element in resizeFactor - public function setResizeFactorElement ($el, $value) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Umberechnungsfaktor %s=%s gesetzt.
\n", - $this->__toString(), - $el, - $value - )); + public final function setResizeFactorElement ($el, $value) { $this->resizeFactorArray[$el] = (float) $value; } // Kontrolliert, ob die Abmasse Schiffsteil->Schiff stimmen public function isShipPartSizeValid () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] isShipPartSizeValid erreicht.
\n", - $this->__toString() - )); return ( ( ( // Already defined ship messurings - ($this->currPart->getWidth() < $this->currShip->getWidth()) - && ($this->currPart->getHeight() < $this->currShip->getDraught()) - && ($this->currPart->getLength() < $this->currShip->getLength()) + ($this->getCurrPart()->getWidth() < $this->currShip->getWidth()) + && ($this->getCurrPart()->getHeight() < $this->currShip->getDraught()) + && ($this->getCurrPart()->getLength() < $this->currShip->getLength()) ) || ( // Ship messurings shall be calculated - ($this->currShip->getWidth() == 0) + ($this->currShip->getWidth() == 0) && ($this->currShip->getHeight() == 0) && ($this->currShip->getLength() == 0) ) // The inserted part must be messured! - ) && ($this->currPart->getWidth() > 0) - && ($this->currPart->getHeight() > 0) - && ($this->currPart->getLength() > 0) + ) && ($this->getCurrPart()->getWidth() > 0) + && ($this->getCurrPart()->getHeight() > 0) + && ($this->getCurrPart()->getLength() > 0) ); } // Kontrolliert, ob die Abmasse Maschinenraum->Schiff stimmen public function isNewSizeValid () { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] isNewSizeValid erreicht.
\n", - $this->__toString() - )); return ( ( // Already defined ship messurings - ($this->newWidth < $this->currShip->getWidth()) + ($this->newWidth < $this->currShip->getWidth()) && ($this->newHeight < $this->currShip->getDraught()) && ($this->newLength < $this->currShip->getLength()) ) || ( // Ship messurings shall be calculated - ($this->currShip->getWidth() == 0) + ($this->currShip->getWidth() == 0) && ($this->currShip->getHeight() == 0) && ($this->currShip->getLength() == 0) ) @@ -370,11 +276,6 @@ class BaseSimulator extends BaseFrameworkSystem { // Masse extrahieren public function extractDimensions ($dim) { - if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] extractDimensions erreicht für %s.
\n", - $this->__toString(), - $this->getPartDescr() - )); - // Abmasse setzen if ((isset($dim)) && (is_array($dim)) && (count($dim) == 3)) { // Abmasse aus Array holen @@ -386,6 +287,15 @@ class BaseSimulator extends BaseFrameworkSystem { throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID); } } + + /** + * Getter for current part instance + * + * @return $currPart Instance of the current ship part object + */ + public final function getCurrPart () { + return $this->currPart; + } } // [EOF]