(no commit message)
[shipsimu.git] / ship-simu / application / ship-simu / main / class_BaseSimulator.php
diff --git a/ship-simu/application/ship-simu/main/class_BaseSimulator.php b/ship-simu/application/ship-simu/main/class_BaseSimulator.php
deleted file mode 100644 (file)
index 4726d29..0000000
+++ /dev/null
@@ -1,392 +0,0 @@
-<?php
-
-// Ein sehr abstraktes Objekt, Abmasse, Beschreibung und Teil-Instanz werden hier gespeichert
-class BaseSimulator extends BaseFrameworkSystem {
-       // Schiffsteilinstanz
-       private $partInstance = null;
-
-       // Abmasse (Breite/Hoehe/Laenge)
-       private $width  = 0;
-       private $height = 0;
-       private $length = 0;
-
-       // Aktuelles Schiff und Schiffsteil
-       private $currShip = null;
-       private $currPart = null;
-
-       // Faktoren zur Erweiterung der Masse. Beispielsweise soll der Maschinenraum groesser wie der Motor sein
-       private $resizeFactorArray = array(
-               'width'  => 1,
-               'height' => 1,
-               'length' => 1
-       );
-
-       // Konstruktor
-       private function __construct ($class) {
-               // Call highest constructor
-               parent::constructor($class);
-
-               if ((defined('DEBUG_CORE')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.<br />\n",
-                       $this->__toString()
-               ));
-
-               // Set part description and class name
-               $this->setPartDescr("Simulator-Basis-Einheit");
-
-               // Etwas aufraeumen, 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 <strong>%s</strong> in class.<br />\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 <strong>%s</strong> from class.<br />\n",
-                       $this->__toString(), $var
-               ));
-               unset($this->$var);
-       }
-
-       // Setter-Methode fuer Laenge
-       public function setLength ($length) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%dm</strong> L&auml;nge gesetzt.<br />\n",
-                       $this->__toString(),
-                       $length
-               ));
-               $this->length = (float) $length;
-       }
-
-       // Setter-Methode fuer Breite
-       public function setWidth ($width) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%dm</strong> Breite gesetzt.<br />\n",
-                       $this->__toString(),
-                       $width
-               ));
-               $this->width = (float) $width;
-       }
-
-       // Setter-Methode fuer Hoehe
-       public function setHeight ($height) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%dm</strong> H&ouml;he gesetzt.<br />\n",
-                       $this->__toString(),
-                       $height
-               ));
-               $this->height = (float) $height;
-       }
-
-       // Getter-Methode fuer Laenge
-       public function getLength () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] L&auml;nge angefordert.<br />\n",
-                       $this->__toString()
-               ));
-               return $this->length;
-       }
-
-       // Getter-Methode fuer Breite
-       public function getWidth () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] L&auml;nge angefordert.<br />\n",
-                       $this->__toString()
-               ));
-               return $this->width;
-       }
-
-       // Getter-Methode fuer Hoehe
-       public function getHeight () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] H&ouml;he angefordert.<br />\n",
-                       $this->__toString()
-               ));
-               return $this->height;
-       }
-
-       // Setter-Methode fuer Teil-Instanz
-       public function setPartInstance ($struct) {
-               $this->partInstance = (Object) $struct;
-       }
-
-       // Getter-Methode fuer Teil-Instanz
-       public function getPartInstance () {
-               if (!isset($this->partInstance)) {
-                       return null;
-               }
-               return $this->partInstance;
-       }
-
-       // 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.<br />\n",
-                               $this->__toString()
-                       ));
-               } else {
-                       // Leere Instanz kann entfernt werden
-                       if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] partInstance wurde entfernt.<br />\n",
-                               $this->__toString()
-                       ));
-                       unset($this->partInstance);
-               }
-       }
-
-       // Prueft ob all Umberechnungsfaktoren gesetzt sind
-       private function isResizeFactorValid () {
-               return (($this->getResizeFactorElement('width')  > 1)
-                       || ($this->getResizeFactorElement('height') > 1)
-                       || ($this->getResizeFactorElement('length') > 1)
-               );
-       }
-
-       // Baut einen Motor in das Schiff ein
-       public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $partInstance) {
-               // Schiff/-steil merken
-               $this->currShip = $shipInstance;
-               $this->currPart = $partInstance;
-
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Maschinenraum mit Motor <strong>%s</strong> wird fuer das Schiff <strong>%s</strong> konstruiert.<br />\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 <strong>%s</strong> vom Typ <strong>%s</strong> passt in das Schiff <strong>%s</strong> hinein.<br />\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'];
-
-                               // 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 <strong>%s</strong> passt in das Schiff <strong>%s</strong> hinein.<br />\n",
-                                               $this->__toString(),
-                                               $this->getPartDescr(),
-                                               $this->currShip->getShipName()
-                                       ));
-                                       $this->setWidth($this->newWidth);
-                                       $this->setHeight($this->newHeight);
-                                       $this->setLength($this->newLength);
-
-                                       // Einige Dinge entfernen...
-                                       $this->removeAllNewAttr();
-                               } else {
-                                       // Passt nicht! Also wieder Exception werfen...
-                                       throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> ist zu gross f&uuml;r das Schiff!",
-                                               $this->currPart->__toString(),
-                                               $this->currPart->getPartDescr(),
-                                               $this->currPart->__toString()
-                                       ), 2);
-                               }
-                       } elseif ($this->currPart != null) {
-                               // Aktuelle Masse setzen
-                               $this->setWidth($this->currPart->getWidth());
-                               $this->setHeight($this->currPart->getHeight());
-                               $this->setLength($this->currPart->getLength());
-                       }
-
-                       // Existiert ein Schiffsteil?
-                       if (!is_null($this->currPart)) {
-                               // Debug-Meldung ausgeben
-                               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Schiffsteil <strong>%s</strong> gefunden.<br />\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();
-                       }
-               } else {
-                       // Exception werfen!
-                       throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <u>%s</u> vom Typ <u>%s</u> passt nicht in das Schiff!",
-                               $this->currPart->realClass,
-                               $this->currPart->getPartDescr(),
-                               $this->currPart->__toString()
-                       ), 1);
-               }
-
-               // Nochmals etwas aufraeumen
-               $this->removeResizeFactorArray();
-               $this->removeCurrShip();
-               $this->removeCurrPart();
-       }
-
-       // Array fuer Umrechnungstabelle entfernen
-       public function removeResizeFactorArray () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeResizeFactor erreicht.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->resizeFactorArray);
-       }
-
-       // Alle newXXX-Attribute entfernen
-       public 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.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->currShip);
-       }
-
-       // Aktuelle Schiff-Instanz entfernen
-       public function removeCurrPart () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeCurrPart erreicht.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->currPart);
-       }
-
-       // Breite entfernen
-       public function removeWidth () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Breite entfernt.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->width);
-       }
-
-       // Hoehe entfernen
-       public function removeHeight () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] H&ouml;he entfernt.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->height);
-       }
-
-       // Laenge entfernen
-       public function removeLength () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] L&auml;nge entfernt.<br />\n",
-                       $this->__toString()
-               ));
-               unset($this->length);
-       }
-
-       // Tiefgang entfernen
-       public function removeDraught () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Tiefgang entfernt.<br />\n",
-                       $this->__toString()
-               ));
-               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)<br />\n",
-                       $this->__toString(),
-                       $el
-               ));
-               if (isset($this->resizeFactorArray[$el])) {
-                       // Element gefunden
-                       return $this->resizeFactorArray[$el];
-               } else {
-                       // Element nicht gefunden!
-                       return 0;
-               }
-       }
-
-       // Setter-Methode fuer Element in resizeFactor
-       public function setResizeFactorElement ($el, $value) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Umberechnungsfaktor <strong>%s</strong>=<strong>%s</strong> gesetzt.<br />\n",
-                       $this->__toString(),
-                       $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.<br />\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())
-                               ) || ( // Ship messurings shall be calculated
-                                          ($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)
-               );
-       }
-
-       // Kontrolliert, ob die Abmasse Maschinenraum->Schiff stimmen
-       public function isNewSizeValid () {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] isNewSizeValid erreicht.<br />\n",
-                       $this->__toString()
-               ));
-               return (
-                       ( // Already defined ship messurings
-                                  ($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->getHeight() == 0)
-                               && ($this->currShip->getLength() == 0)
-                       )
-               );
-       }
-
-       // Masse extrahieren
-       public function extractDimensions ($dim) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] extractDimensions erreicht f&uuml;r <strong>%s</strong>.<br />\n",
-                       $this->__toString(),
-                       $this->getPartDescr()
-               ));
-
-               // Abmasse setzen
-               if ((isset($dim)) && (is_array($dim)) && (count($dim) == 3)) {
-                       // Abmasse aus Array holen
-                       $this->setWidth($dim[0]);
-                       $this->setHeight($dim[1]);
-                       $this->setLength($dim[2]);
-               } else {
-                       // Nicht gefundene Abmasse!
-                       throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
-               }
-       }
-}
-
-// [EOF]
-?>