/* Copyright (C) 2004 - 2014 A.Vontobel
* Classes in drawj2d.bgd are derived from fachwerk.sourceforge.net, 2014
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The license is in LICENCE-GPL.txt.
* If not, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
*/
package net.sf.drawj2d.bgd;
import java.util.*;
import java.io.BufferedReader;
// ---------------------------------------------------------------------------
public class clBGD {
ArrayList hgLinien = new ArrayList();
ArrayList hgPunkte = new ArrayList();
ArrayList hgKreise = new ArrayList();
ArrayList hgBogen = new ArrayList();
private static final int LINE = 1;
private static final int POLYLINE = 2;
private static final int LWPOLYLINE = 3;
private static final int CIRCLE = 4;
private static final int POINT = 5;
private static final int TEXT = 6;
private static final int ARC = 7;
private static final int INSERT = 8;
private static final int SOLID = 9;
private static final int DIMENSION = 10;
private static final int FEHLER = -1;
private final boolean verbose;
public clBGD(String datei, boolean verbose) {
this.verbose = verbose;
einlesenBGD(datei);
}
public clBGD(BufferedReader eingabe, boolean verbose) {
this.verbose = verbose;
clParserBGD doc = new clParserBGD(eingabe);
einlesenDOC(doc);
}
private boolean einlesenBGD(String datei) {
if (verbose) System.out.println("BGD: " + datei);
clParserBGD doc = new clParserBGD(datei);
boolean success = einlesenDOC(doc);
return success;
}
private boolean einlesenDOC(clParserBGD doc) {
if (doc == null) {
System.err.println("Error in clBGD: doc == null");
System.err.println("Reading bgd failed");
return false;
}
String entityName;
int entityNameNr = 0;
clHintergrundLinie aktLinie = null;
clHintergrundPunkt aktPunkt = null;
clHintergrundKreis aktKreis = null;
clHintergrundBogen aktBogen = null;
double[] data;
try {
while (doc.hasMoreElements()) {
entityNameNr = 0;
entityName = doc.getEntityName();
if (entityName.equals("Line")) entityNameNr = LINE;
if (entityName.equals("Circle")) entityNameNr = CIRCLE;
if (entityName.equals("Point")) entityNameNr = POINT;
if (entityName.equals("Arc")) entityNameNr = ARC;
if (entityName.equals("Fehler")) entityNameNr = FEHLER;
switch (entityNameNr) {
case (POINT):
data = doc.getEntity();
aktPunkt = new clHintergrundPunkt(data[0], data[2]);
hgPunkte.add(aktPunkt);
break;
case (LINE):
data = doc.getEntity();
aktLinie = new clHintergrundLinie(data[0], data[2], data[3], data[5]);
hgLinien.add(aktLinie);
break;
case (CIRCLE):
data = doc.getEntity();
aktKreis = new clHintergrundKreis(data[0], data[2], data[3]);
hgKreise.add(aktKreis);
break;
case (ARC):
data = doc.getEntity();
aktBogen = new clHintergrundBogen(data[0], data[2], data[3], data[4], data[5]);
hgBogen.add(aktBogen);
break;
case FEHLER:
System.err.println("Error while parsing entity.");
break;
default:
System.err.println("UNKNOWN entity: " + entityName);
}
}
}
catch (Exception e) {
System.err.println(e.getLocalizedMessage());
return false;
}
if (verbose) System.out.println("");
return true;
}
public boolean skaliere(double faktorx, double faktorz) {
if (Math.abs(faktorx) < 1E-9 || Math.abs(faktorz) < 1E-9) {
System.err.println("factor < 1E-9 not allowed");
return false;
}
if (faktorx == 1 && faktorz == 1) return true;
if (Math.abs(faktorx) != Math.abs(faktorz)) {
if (!hgKreise.isEmpty()) {
System.out.println("Hintergrundkreise koennen nicht verzerrt werden.");
}
if (!hgBogen.isEmpty()) {
System.out.println("Hintergrundboegen koennen nicht verzerrt werden.");
}
}
clHintergrundLinie aktuell;
for (Iterator it = hgLinien.iterator(); it.hasNext();) {
aktuell = (clHintergrundLinie) it.next();
aktuell.skaliere(faktorx, faktorz);
}
clHintergrundPunkt aktpkt;
for (Iterator it = hgPunkte.iterator(); it.hasNext();) {
aktpkt = (clHintergrundPunkt) it.next();
aktpkt.skaliere(faktorx, faktorz);
}
clHintergrundKreis aktkreis;
for (Iterator it = hgKreise.iterator(); it.hasNext();) {
aktkreis = (clHintergrundKreis) it.next();
aktkreis.skaliere(faktorx, faktorz);
}
clHintergrundBogen aktbogen;
for (Iterator it = hgBogen.iterator(); it.hasNext();) {
aktbogen = (clHintergrundBogen) it.next();
aktbogen.skaliere(faktorx, faktorz);
}
return true;
}
public void verschiebe(double dx, double dz) {
if (dx == 0 && dz == 0) return;
clHintergrundLinie aktuell;
for (Iterator it = hgLinien.iterator(); it.hasNext();) {
aktuell = (clHintergrundLinie) it.next();
aktuell.verschiebe(dx, dz);
}
clHintergrundPunkt aktpkt;
for (Iterator it = hgPunkte.iterator(); it.hasNext();) {
aktpkt = (clHintergrundPunkt) it.next();
aktpkt.verschiebe(dx, dz);
}
clHintergrundKreis aktkreis;
for (Iterator it = hgKreise.iterator(); it.hasNext();) {
aktkreis = (clHintergrundKreis) it.next();
aktkreis.verschiebe(dx, dz);
}
clHintergrundBogen aktbogen;
for (Iterator it = hgBogen.iterator(); it.hasNext();) {
aktbogen = (clHintergrundBogen) it.next();
aktbogen.verschiebe(dx, dz);
}
}
/** Rotiert die Hintergrundzeichnung im Uhrzeigersinn.
* @param rot Rotation in Radianten */
public void rotiere(double rot) {
if (rot == 0) return;
clHintergrundLinie aktuell;
for (Iterator it = hgLinien.iterator(); it.hasNext();) {
aktuell = (clHintergrundLinie) it.next();
aktuell.rotiere(rot);
}
clHintergrundPunkt aktpkt;
for (Iterator it = hgPunkte.iterator(); it.hasNext();) {
aktpkt = (clHintergrundPunkt) it.next();
aktpkt.rotiere(rot);
}
clHintergrundKreis aktkreis;
for (Iterator it = hgKreise.iterator(); it.hasNext();) {
aktkreis = (clHintergrundKreis) it.next();
aktkreis.rotiere(rot);
}
clHintergrundBogen aktbogen;
for (Iterator it = hgBogen.iterator(); it.hasNext();) {
aktbogen = (clHintergrundBogen) it.next();
aktbogen.rotiere(rot);
}
}
/** Gibt die Liste mit den Hintergrund-Linien zurück.
*@return ArrayList Hintergrundlinien
*/
public ArrayList getHgLinien() {
return hgLinien;
}
/** Gibt die Liste mit den Hintergrund-Punkten zurück.
*@return ArrayList Hintergrundpunkte
*/
public ArrayList getHgPunkte() {
return hgPunkte;
}
/** Gibt die Liste mit den Hintergrund-Kreisen zurück.
* @return ArrayList Hintergrundkreise
*/
public ArrayList getHgKreise() {
return hgKreise;
}
/** Gibt die Liste mit den Hintergrund-Bögen zurück.
* @return ArrayList Hintergrundbogen
*/
public ArrayList getHgBogen() {
return hgBogen;
}
void testen() {
clHintergrundLinie aktuell;
clHintergrundPunkt aktpkt;
System.out.println("");
for (Iterator it = hgLinien.iterator(); it.hasNext();) {
aktuell = (clHintergrundLinie) it.next();
System.out.print("von " + aktuell.getVon()[0] + " " + aktuell.getVon()[1]);
System.out.println(" bis " + aktuell.getBis()[0] + " " + aktuell.getBis()[1]);
}
for (Iterator it = hgPunkte.iterator(); it.hasNext();) {
aktpkt = (clHintergrundPunkt) it.next();
System.out.println("Punkt " + aktpkt.getPkt()[0] + " " + aktpkt.getPkt()[1]);
}
}
public static void main(String[] args) {
System.out.println("Open file: " + args[0]);
new clBGD(args[0], true);
}
}
Ads help maintain this website.