Make first real commit: copy of CaRMetal 4.2.8

This commit is contained in:
Glen Whitney 2018-09-04 22:51:42 -04:00
parent 002acfc88e
commit c312811084
1120 changed files with 226843 additions and 1 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
public interface ChangedListener {
public void notifyChanged();
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,442 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.PopupMenu;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CheckboxMenuItemAction;
import rene.gui.ChoiceAction;
import rene.gui.DoActionListener;
import rene.gui.Global;
import rene.gui.MenuItemAction;
import rene.lister.Lister;
import rene.lister.ListerMouseEvent;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.objects.AngleObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.ExpressionObject;
import rene.zirkel.objects.FixedAngleObject;
import rene.zirkel.objects.FunctionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PrimitiveCircleObject;
import rene.zirkel.objects.PrimitiveLineObject;
public class ConstructionDisplayPanel extends JEricPanel implements
DoActionListener, ActionListener, ClipboardOwner {
private static final long serialVersionUID=1L;
private static int control_height=25;
private JEricPanel controls;
public Lister V;
public Vector W;
Construction C;
ZirkelCanvas ZC;
JComboBox Ch;
CheckboxMenuItemAction Visible;
boolean ShowVisible=true;
CheckboxMenuItemAction Sort, Description, Size, Formula;
public static String Choices[]={"all", "points", "lines", "circles",
"angles", "expressions", "other"};
public int State=0;
PopupMenu PM;
JButton Menu;
@Override
public void paintComponent(Graphics g) {
Dimension d=getSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height);
super.paintComponent(g);
}
public ConstructionDisplayPanel(final ZirkelCanvas zc) {
ZC=zc;
C=ZC.getConstruction();
V=new Lister();
V.setMode(true, false, true, true);
V.addActionListener(this);
State=Global.getParameter("constructiondisplay.state", 0);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setOpaque(false);
controls=new JEricPanel();
controls.setLayout(new BoxLayout(controls, BoxLayout.X_AXIS));
controls.setOpaque(false);
Ch=new ChoiceAction(this, "choices");
for (final String choice : Choices) {
Ch.addItem(Global.name("constructiondisplay."+choice));
}
controls.add(Ch);
Menu=new ButtonAction(this, "?", "Menu");
controls.add(Menu);
add(controls);
setListerState();
makePopup();
add(V);
}
// Only called by LeftPanelContent init method :
public void fixPanelSize(int w, int h) {
fixsize(this, w, h);
fixsize(V, w, h-control_height);
fixsize(controls, w, control_height);
controls.revalidate();
}
private static void fixsize(final JComponent cp, final int w, final int h) {
final Dimension d=new Dimension(w, h);
cp.setMaximumSize(d);
cp.setMinimumSize(d);
cp.setPreferredSize(d);
cp.setSize(d);
}
public void reload() {
V.clear();
C=ZC.getConstruction();
Enumeration e=null;
if (Global.getParameter("constructiondisplay.sort", true)) {
e=C.getSortedElements();
} else {
e=C.elements();
}
W=new Vector();
outer:
while (e.hasMoreElements()) {
final ConstructionObject o=(ConstructionObject) e.nextElement();
// if ((eric.JMacrosTools.CurrentJZF.restrictedSession)
// && (o.isSuperHidden()))
// continue outer;
if (ShowVisible&&o.mustHide(ZC)) {
continue outer;
}
if (ZC.job_isTargets()&&o.isSuperHidden()) {
continue outer;
}
if (ZC.isRestricted()&&o.isSuperHidden()) {
continue outer;
}
switch (State) {
case 0:
break;
case 1:
if (!(o instanceof PointObject)) {
continue outer;
}
break;
case 2:
if (!(o instanceof PrimitiveLineObject)
||(o instanceof FixedAngleObject)) {
continue outer;
}
break;
case 3:
if (!(o instanceof PrimitiveCircleObject)) {
continue outer;
}
break;
case 4:
if (!(o instanceof AngleObject||o instanceof FixedAngleObject)) {
continue outer;
}
break;
case 5:
if (!(o instanceof ExpressionObject||o instanceof FunctionObject)) {
continue outer;
}
break;
case 6:
if (o instanceof PointObject
||o instanceof PrimitiveLineObject
||o instanceof PrimitiveCircleObject
||o instanceof AngleObject
||o instanceof ExpressionObject
||o instanceof FunctionObject) {
continue outer;
}
break;
}
V.addElement(o);
W.addElement(o);
}
//V.showLast();
updateDisplay();
}
public void updateDisplay() {
V.updateDisplay();
}
@Override
public void doAction(final String o) {
if (o.equals("Edit")) {
final int selected[]=V.getSelectedIndices();
if (selected.length==0) {
return;
}
if (selected.length==1) {
((ConstructionObject) W.elementAt(selected[0])).edit(ZC, true, false);
} else {
final Vector v=new Vector();
for (final int element : selected) {
v.addElement(W.elementAt(element));
}
ZC.validate();
}
ZC.repaint();
} else if (o.equals("Copy")) {
try {
final ByteArrayOutputStream ba=new ByteArrayOutputStream(
50000);
final PrintWriter po=new PrintWriter(new OutputStreamWriter(
ba), true);
V.save(po);
po.close();
final String S=ba.toString();
final Clipboard clip=getToolkit().getSystemClipboard();
final StringSelection sel=new StringSelection(S);
clip.setContents(sel, this);
} catch (final Exception e) {
}
} else if (o.equals("Delete")) {
final int selected[]=V.getSelectedIndices();
if (selected.length==0) {
return;
}
final Vector v=new Vector();
for (final int element : selected) {
v.addElement(W.elementAt(element));
}
ZC.delete(v);
ZC.repaint();
ZC.reset();
reload();
} else if (o.equals("Hide")) {
final int selected[]=V.getSelectedIndices();
if (selected.length==0) {
return;
}
for (final int element : selected) {
final ConstructionObject oc=(ConstructionObject) W.elementAt(element);
oc.setHidden(!oc.isHidden());
}
ZC.repaint();
updateDisplay();
} else if (o.equals("SuperHide")) {
final int selected[]=V.getSelectedIndices();
if (selected.length==0) {
return;
}
for (final int element : selected) {
final ConstructionObject oc=(ConstructionObject) W.elementAt(element);
oc.setSuperHidden(true);
}
ZC.repaint();
updateDisplay();
} else if (o.equals("HighLight")) {
final int selected[]=V.getSelectedIndices();
if (selected.length==0) {
return;
}
for (final int element : selected) {
final ConstructionObject oc=(ConstructionObject) W.elementAt(element);
oc.setStrongSelected(true);
}
final Graphics g=ZC.getGraphics();
if (g!=null) {
ZC.paint(g);
g.dispose();
try {
Thread.sleep(200);
} catch (final Exception e) {
}
}
for (final int element : selected) {
final ConstructionObject oc=(ConstructionObject) W.elementAt(element);
oc.setStrongSelected(false);
}
ZC.repaint();
if (selected.length==1) {
final ConstructionObject oc=(ConstructionObject) W.elementAt(selected[0]);
ZC.setConstructionObject(oc);
}
} else if (o.equals("Menu")) {
displayPopup(V.L, 10, 10);
}
ZC.requestFocus();
}
public void itemToggleAction(final String o) {
if (o.equals("Sort")) {
Sort.setState(!Sort.getState());
itemAction("Sort", Sort.getState());
} else if (o.equals("Visible")) {
Visible.setState(!Visible.getState());
itemAction("Visible", Visible.getState());
}
}
@Override
public void itemAction(final String o, final boolean flag) {
if (o.equals("Sort")) {
Global.setParameter("constructiondisplay.sort", Sort.getState());
reload();
} else if (o.equals("Visible")) {
ShowVisible=Visible.getState();
reload();
} else if (o.equals("Description")) {
Global.setParameter("constructiondisplay.listerstate",
ConstructionObject.DescriptionState);
setListerState();
updateDisplay();
} else if (o.equals("Size")) {
Global.setParameter("constructiondisplay.listerstate",
ConstructionObject.SizeState);
setListerState();
updateDisplay();
} else if (o.equals("Formula")) {
Global.setParameter("constructiondisplay.listerstate",
ConstructionObject.FormulaState);
setListerState();
updateDisplay();
} else if (flag) {
State=Ch.getSelectedIndex();
Global.setParameter("constructiondisplay.state", State);
reload();
}
}
public void setListerState() {
final int state=Global.getParameter("constructiondisplay.listerstate",
ConstructionObject.SizeState);
V.setState(state);
if (PM!=null) {
Description.setState(state==ConstructionObject.DescriptionState);
Size.setState(state==ConstructionObject.SizeState);
Formula.setState(state==ConstructionObject.FormulaState);
}
}
// @Override
// public Dimension getPreferredSize() {
// return new Dimension(Global.getParameter(
// "options.constructiondisplay.width", 200), 400);
// }
/**
* React on click events for the construction list
*/
@Override
public void actionPerformed(final ActionEvent e) {
if (e.getSource()==V&&(e instanceof ListerMouseEvent)) {
final ListerMouseEvent em=(ListerMouseEvent) e;
if (em.rightMouse()) {
displayPopup(em.getEvent().getComponent(),
em.getEvent().getX(), em.getEvent().getY());
} else {
if (em.clickCount()>=2) {
doAction("Edit");
} else {
doAction("HighLight");
}
}
}
}
/**
* Display the popup menu. Create it, if necessary.
*
* @param e
* mouse event
*/
public void displayPopup(final Component c, final int x, final int y) {
PM.show(c, x, y);
}
public void makePopup() {
PM=new PopupMenu();
PM.add(new MenuItemAction(this,
Global.name("constructiondisplay.edit"), "Edit"));
PM.addSeparator();
PM.add(new MenuItemAction(this,
Global.name("constructiondisplay.hide"), "Hide"));
PM.add(new MenuItemAction(this, Global.name("constructiondisplay.superhide"), "SuperHide"));
PM.addSeparator();
PM.add(new MenuItemAction(this, Global.name("constructiondisplay.delete"), "Delete"));
PM.addSeparator();
Description=new CheckboxMenuItemAction(this, Global.name("constructiondisplay.description"), "Description");
Description.setState(Global.getParameter(
"constructiondisplay.description", false));
PM.add(Description);
Size=new CheckboxMenuItemAction(this, Global.name("constructiondisplay.size"), "Size");
Description.setState(Global.getParameter("constructiondisplay.size",
true));
PM.add(Size);
Formula=new CheckboxMenuItemAction(this, Global.name("constructiondisplay.formula"), "Formula");
Description.setState(Global.getParameter("constructiondisplay.formula",
false));
PM.add(Formula);
PM.addSeparator();
PM.add(new MenuItemAction(this,
Global.name("constructiondisplay.copy"), "Copy"));
V.L.add(PM);
PM.addSeparator();
Visible=new CheckboxMenuItemAction(this, Global.name("constructiondisplay.visible"), "Visible");
Visible.setState(true);
PM.add(Visible);
Sort=new CheckboxMenuItemAction(this, Global.name("constructiondisplay.sorted"), "Sort");
Sort.setState(Global.getParameter("constructiondisplay.sort", true));
PM.add(Sort);
setListerState();
}
@Override
public void lostOwnership(final Clipboard clipboard,
final Transferable contents) {
}
public void setListingBackground(final Color c) {
V.setListingBackground(c);
}
}

View file

@ -0,0 +1,44 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
public class ConstructionException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
String S;
public ConstructionException(final String s) {
super(s);
S = s;
}
public String getDescription() {
return S;
}
@Override
public String toString() {
return S;
}
}

View file

@ -0,0 +1,83 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
import java.util.Enumeration;
import java.util.Vector;
/**
* This is used to generate unique numbers for construction objects. Instances
* will be static in their classes. There is also an alternative count, which
* can be used for macro generation.
*/
public class Count {
static Vector Counts = new Vector();
int N, BackupN;
boolean Fixed = false;
public Count() {
reset();
Counts.addElement(this);
}
public synchronized int next() {
if (Fixed)
return 0;
N++;
return N;
}
public synchronized void reset() {
N = 0;
}
public synchronized void setAlternate(final boolean flag) {
if (flag) {
BackupN = N;
N = 0;
} else
N = BackupN;
}
static synchronized public void resetAll() {
final Enumeration e = Counts.elements();
while (e.hasMoreElements())
((Count) e.nextElement()).reset();
}
static synchronized public void setAllAlternate(final boolean flag) {
final Enumeration e = Counts.elements();
while (e.hasMoreElements())
((Count) e.nextElement()).setAlternate(flag);
}
public synchronized void fix(final boolean flag) {
Fixed = flag;
}
static synchronized public void fixAll(final boolean flag) {
final Enumeration e = Counts.elements();
while (e.hasMoreElements())
((Count) e.nextElement()).fix(flag);
}
}

View file

@ -0,0 +1,88 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
// file: ConstructionObject.java
import java.util.Enumeration;
import rene.zirkel.objects.ConstructionObject;
public class DepList implements Enumeration {
ConstructionObject E[] = new ConstructionObject[8];
int N = 0, I;
public void reset() {
N = 0;
}
public void add(final ConstructionObject o) {
if (have(o))
return;
if (N < E.length)
E[N++] = o;
else {
final ConstructionObject e[] = new ConstructionObject[E.length + 8];
for (int i = 0; i < E.length; i++)
e[i] = E[i];
E = e;
E[N++] = o;
}
}
public boolean have(final ConstructionObject o) {
for (int i = 0; i < N; i++)
if (E[i] == o)
return true;
return false;
}
public Enumeration elements() {
I = 0;
return this;
}
public boolean hasMoreElements() {
return I < N;
}
public Object nextElement() {
return E[I++];
}
public ConstructionObject[] getArray() {
final ConstructionObject o[] = new ConstructionObject[N];
for (int i = 0; i < N; i++)
o[i] = E[i];
return o;
}
public void translate() {
for (int i = 0; i < N; i++)
E[i] = E[i].getTranslation();
}
public int size() {
return N;
}
}

View file

@ -0,0 +1,811 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
import java.util.Vector;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.ZirkelFrame;
import rene.zirkel.constructors.AngleConstructor;
import rene.zirkel.constructors.AreaConstructor;
import rene.zirkel.constructors.CircleConstructor;
import rene.zirkel.constructors.ExpressionConstructor;
import rene.zirkel.constructors.FunctionConstructor;
import rene.zirkel.constructors.IntersectionConstructor;
import rene.zirkel.constructors.LineConstructor;
import rene.zirkel.constructors.MidpointConstructor;
import rene.zirkel.constructors.ObjectConstructor;
import rene.zirkel.constructors.ParallelConstructor;
import rene.zirkel.constructors.PlumbConstructor;
import rene.zirkel.constructors.PointConstructor;
import rene.zirkel.constructors.QuadricConstructor;
import rene.zirkel.constructors.RayConstructor;
import rene.zirkel.constructors.SegmentConstructor;
import rene.zirkel.macro.Macro;
import rene.zirkel.macro.MacroRunner;
import rene.zirkel.objects.AngleObject;
import rene.zirkel.objects.CircleObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.ExpressionObject;
import rene.zirkel.objects.FixedAngleObject;
import rene.zirkel.objects.FixedCircleObject;
import rene.zirkel.objects.IntersectionObject;
import rene.zirkel.objects.LineObject;
import rene.zirkel.objects.PlumbObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PrimitiveCircleObject;
import rene.zirkel.objects.SegmentObject;
import rene.zirkel.objects.TwoPointLineObject;
public class Interpreter {
Construction C;
public Interpreter(final Construction c) {
C = c;
}
/**
* This is to interpret a single line of input in descriptive mode or a
* single line read from a construction description in a file.
*/
public void interpret(final ZirkelCanvas zc, String s, final String comment)
throws ConstructionException {
boolean Parameter = false, Target = false, Prompt = false;
final Vector V = C.V;
final int VN = V.size(); // note the current construction size
int k;
// Look for special start tags:
if ((k = startTest("parameter", s)) >= 0)
// Parameter objects are set at the end of the function.
{
Parameter = true;
s = s.substring(k).trim();
} else if (s.toLowerCase().equals(Global.name("showall"))
|| s.toLowerCase().equals("showall"))
// This will show all objects even, if there are targets
{
C.ShowAll = true;
return;
} else if (s.toLowerCase().equals(Global.name("invisible"))
|| s.toLowerCase().equals("invisible"))
// This will superhide all objects
{
C.SuperHide = true;
return;
} else if ((k = startTest("target", s)) >= 0)
// Target objects are either set immediate (name only) or
// at the end of the function.
{
Target = true;
s = s.substring(k).trim();
final ConstructionObject o = C.find(s);
// see, if the target ist constructable from the
// parameters, which are already marked cosntructable.
C.determineConstructables();
if (o != null && o.isFlag()) {
o.setTarget(true);
C.addTarget(o);
return;
} else {
Target = true;
}
} else if ((k = startTest("prompt", s)) >= 0) {
Prompt = true;
s = s.substring(k).trim();
if (C.find(s) != null) {
C.PromptFor.addElement(s);
return;
}
}
// Interpret s. First decompose into function and parameters:
String name = "", function = "";
final String params[] = new String[16];
int NParams = 0, n;
if ((n = s.indexOf('=')) >= 0) {
name = s.substring(0, n).trim();
s = s.substring(n + 1).trim();
}
int bracketn = 0;
if (s.startsWith("\"")) {
bracketn = s.indexOf("\"", 1);
}
if (bracketn < 0) {
throw new ConstructionException("exception.brackets");
}
if ((n = s.indexOf('(', bracketn)) >= 0) {
function = s.substring(0, n).trim();
if (function.startsWith("\"") && function.endsWith("\"")
&& function.length() > 1) {
function = function.substring(1, function.length() - 1);
}
s = s.substring(n + 1).trim();
if (!s.endsWith(")")) {
throw new ConstructionException("exception.brackets");
}
final char a[] = s.substring(0, s.length() - 1).toCharArray();
int ia = 0;
int BCount = 0;
while (ia < a.length && NParams < params.length) {
final int ia0 = ia;
while (ia < a.length && (BCount > 0 || a[ia] != ',')) {
if (a[ia] == '\"') {
ia++;
while (ia < a.length && a[ia] != '\"') {
ia++;
}
if (ia >= a.length) {
throw new ConstructionException(Global.name("exception.quotes"));
}
ia++;
} else if (a[ia] == '(') {
BCount++;
ia++;
} else if (a[ia] == ')') {
if (BCount > 0) {
BCount--;
}
else {
throw new ConstructionException(Global.name("exception.brackets"));
}
ia++;
} else {
ia++;
}
}
params[NParams++] = new String(a, ia0, ia - ia0).trim();
ia++;
}
} else {
function = s;
}
final String f = function;
// Interpret special functions:
if (NParams == 3 && ptest(f, "window"))
// window size
{
try {
final double x = new Double(params[0]).doubleValue();
final double y = new Double(params[1]).doubleValue();
final double w = new Double(params[2]).doubleValue();
C.setXYW(x, y, w);
zc.recompute();
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.value"));
}
return;
}
if ((NParams == 1 || NParams == 2) && ptest(f, "color"))
// color for object or default color
{
int i = 0;
for (i = 0; i < ZirkelFrame.ColorStrings.length; i++) {
if (test(params[0], "colors", ZirkelFrame.ColorStrings[i])) {
break;
}
}
if (i < ZirkelFrame.ColorStrings.length) {
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setColor(i);
} else {
C.DefaultColor = i;
}
} else {
throw new ConstructionException(Global.name("exception.color"));
}
return;
}
if ((NParams == 1 || NParams == 2) && ptest(f, "thickness"))
// thickness for objects or default thickness
{
int i;
for (i = 0; i < ZirkelFrame.ColorTypes.length; i++) {
if (test(params[0], "color.type", ZirkelFrame.ColorTypes[i])) {
break;
}
}
if (i < ZirkelFrame.ColorTypes.length) {
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setColorType(i);
} else {
C.DefaultColorType = i;
}
} else {
throw new ConstructionException(Global.name("exception.colortype"));
}
return;
}
if ((NParams == 1 || NParams == 2) && ptest(f, "type"))
// point type for point or default point type
{
int i;
for (i = 0; i < ZirkelFrame.PointTypes.length; i++) {
if (test(params[0], "point.type", ZirkelFrame.PointTypes[i])) {
break;
}
}
if (i < ZirkelFrame.PointTypes.length) {
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null || !(o instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.notfound"));
}
((PointObject) o).setType(i);
} else {
C.DefaultType = i;
}
} else {
throw new ConstructionException(Global.name("exception.type"));
}
return;
}
if ((NParams == 1 || NParams == 2) && ptest(f, "partial"))
// partail view for circle or line or default partial view
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (o instanceof PrimitiveCircleObject) {
((PrimitiveCircleObject) o).setPartial(true);
}
if (o instanceof LineObject) {
((LineObject) o).setPartial(true);
}
return;
}
final boolean partial = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (o instanceof PrimitiveCircleObject) {
((PrimitiveCircleObject) o).setPartial(partial);
}
if (o instanceof LineObject) {
((LineObject) o).setPartial(partial);
}
} else {
C.Partial = partial;
C.PartialLines = partial;
}
return;
}
if ((NParams == 1 || NParams == 2) && ptest(f, "hide"))
// hide object or toggle show hidden state
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setHidden(true);
return;
}
final boolean hidden = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setHidden(hidden);
} else {
C.Hidden = hidden;
}
return;
}
if (NParams == 2 && ptest(f, "invisible"))
// totally invisible for an object
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setSuperHidden(true);
return;
}
final boolean hidden = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setSuperHidden(hidden);
} else {
throw new ConstructionException(Global.name("exception.notfound"));
}
return;
}
if (NParams >= 1 && ptest(f, "back"))
// push object into background
{
if (NParams == 1) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setBack(true);
return;
}
final boolean back = truetest(params[0]);
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setBack(back);
return;
}
if (NParams >= 1 && ptest(f, "acute"))
// set acute state of angle, or set default acute state
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setObtuse(false);
return;
}
final boolean acute = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setObtuse(!acute);
} else {
C.Obtuse = !acute;
}
return;
}
if (NParams >= 1 && ptest(f, "obtuse"))
// revorse of acute
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setObtuse(false);
return;
}
final boolean obtuse = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setObtuse(obtuse);
} else {
C.Obtuse = obtuse;
}
return;
}
if (NParams >= 1 && ptest(f, "solid"))
// set solid state of object, or default solid state
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setSolid(false);
return;
}
final boolean solid = truetest(params[0]);
if (NParams == 2) {
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setSolid(solid);
} else {
C.Solid = solid;
}
return;
}
if (NParams == 3 && ptest(f, "restrict"))
// set range for circle arcs
{
try {
final PrimitiveCircleObject c = (PrimitiveCircleObject) C.find(params[0]);
c.setRange(params[1], params[2]);
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.notfound"));
}
return;
}
if (NParams >= 1 && ptest(f, "fill"))
// set fill state for objects: fill(o), fill(t/f,o)
{
if (NParams == 1) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setFilled(true);
o.setBack(true);
return;
}
final boolean fill = truetest(params[0]);
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setFilled(fill);
o.setBack(fill);
return;
}
if (NParams >= 1 && ptest(f, "valid"))
// set always valid state of intersection
{
if (NParams == 1) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (o instanceof PlumbObject) {
((PlumbObject) o).setRestricted(false);
} else if (o instanceof IntersectionObject) {
((IntersectionObject) o).setRestricted(false);
}
return;
}
truetest(params[0]);
final ConstructionObject o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (o instanceof PlumbObject) {
((PlumbObject) o).setRestricted(false);
} else if (o instanceof IntersectionObject) {
((IntersectionObject) o).setRestricted(false);
}
return;
}
if (NParams >= 1 && (ptest(f, "rename") || ptest(f, "name")))
// works like name
{
if (NParams == 1 && !truecheck(params[0])) {
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setShowName(true);
return;
}
ConstructionObject o = C.find(params[0]);
if (o == null) {
final boolean shownames = truetest(params[0]);
if (NParams == 2) {
o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setShowName(truetest(params[0]));
} else {
C.ShowNames = shownames;
}
} else if (!params[1].equals("")) {
o.setName(params[1]);
}
return;
}
if (NParams == 2 && ptest(f, "away"))
// keep interesction away from object
{
final ConstructionObject o = C.find(params[0]);
final ConstructionObject p = C.find(params[1]);
if (!(o instanceof IntersectionObject) || !(p instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.parameter"));
}
((IntersectionObject) o).setAway(p.getName());
return;
}
if (NParams == 2 && ptest(f, "close"))
// keep interesction close to object
{
final ConstructionObject o = C.find(params[0]);
final ConstructionObject p = C.find(params[1]);
if (!(o instanceof IntersectionObject)
|| !(p instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.parameter"));
}
((IntersectionObject) o).setAway(p.getName(), false);
return;
}
if (NParams >= 1 && ptest(f, "value"))
// set the size of an object, value of expression, position of point
// or toggle value display
{
if (NParams == 1 && !truecheck(params[0])) // value(o)
{
final ConstructionObject o = C.find(params[0]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setShowValue(true);
return;
}
ConstructionObject o = C.find(params[0]);
if (o == null) // value(t/f), value(t/f,o)
{
try {
truetest(params[0]);
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (NParams == 2) {
o = C.find(params[1]);
if (o == null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
o.setShowValue(truetest(params[0]));
} else {
C.ShowValues = true;
}
} else if (NParams == 2) // value(o,x)
{
if (o instanceof SegmentObject) {
final SegmentObject os = (SegmentObject) o;
if (!os.canFix()) {
throw new ConstructionException(Global.name("exception.canfix"));
}
os.setFixed(true, params[1]);
os.validate();
} else if (o instanceof CircleObject) {
final CircleObject os = (CircleObject) o;
if (!os.canFix()) {
throw new ConstructionException(Global.name("exception.canfix"));
}
os.setFixed(true, params[1]);
os.validate();
} else if (o instanceof FixedCircleObject) {
final FixedCircleObject os = (FixedCircleObject) o;
os.setFixed(params[1]);
os.validate();
} else if (o instanceof AngleObject) {
final AngleObject os = (AngleObject) o;
if (!os.canFix()) {
throw new ConstructionException(Global.name("exception.canfix"));
}
os.setFixed(params[1]);
os.validate();
} else if (o instanceof FixedAngleObject) {
final FixedAngleObject os = (FixedAngleObject) o;
os.setFixed(params[1]);
os.validate();
} else if (o instanceof ExpressionObject) {
final ExpressionObject os = (ExpressionObject) o;
os.setFixed(params[1]);
os.validate();
} else {
throw new ConstructionException(Global.name("exception.parameter"));
}
} else if (NParams == 3) // value(P,x,y)
{
if (o instanceof PointObject) {
final PointObject os = (PointObject) o;
if (!os.moveablePoint()) {
throw new ConstructionException(Global.name("exception.canfix"));
}
os.setFixed(params[1], params[2]);
os.validate();
} else {
throw new ConstructionException(Global.name("exception.parameter"));
}
} else {
throw new ConstructionException(Global.name("exception.parameter"));
}
return;
}
// Look for the normal construction functions:
final int i = findFunction(function, zc);
if (i >= 0) {
for (int j = 0; j < NParams; j++) {
params[j] = extend(params[j]);
}
OCs[i].construct(C, name, params, NParams);
// the following are for macro definition in scripts
if (Parameter) {
if (VN >= V.size()) {
throw new ConstructionException(Global.name("exception.macroparameter"));
}
final ConstructionObject o = C.lastButN(0);
o.setMainParameter(true);
if (o.isMainParameter()) {
C.addParameter(o);
C.Prompts.addElement(comment);
} else {
throw new ConstructionException(Global.name("exception.macroparameter"));
}
} else if (Target) {
if (VN + 1 != V.size()) {
throw new ConstructionException(Global.name("exception.macrotarget"));
}
final ConstructionObject o = C.lastButN(0);
o.setTarget(true);
C.addTarget(o);
} else if (Prompt) {
final ConstructionObject o = C.lastButN(0);
C.PromptFor.addElement(o.getName());
}
return;
}
// Finally, look for macros:
final Macro m = zc.chooseMacro(function);
if (m == null) {
throw new ConstructionException(Global.name("exception.function"));
}
MR.setMacro(m, zc);
// System.out.println("nom:"+m.getName());
MR.run(zc, C, name, params, NParams);
// Only for macro definition in scripts
if (Target) {
final ConstructionObject o = C.find(name);
if (o == null) {
throw new ConstructionException(Global.name("exception.macrotarget"));
}
o.setTarget(true);
C.addTarget(o);
} else if (Prompt) {
final ConstructionObject o = C.find(name);
if (o != null) {
C.PromptFor.addElement(o.getName());
}
}
}
public void interpret(final ZirkelCanvas zc, final String s)
throws ConstructionException {
interpret(zc, s, "");
}
static public boolean truetest(String s) throws ConstructionException {
s = s.toLowerCase();
if (s.equals("true") || s.equals(Global.name("true"))) {
return true;
}
if (s.equals("false") || s.equals(Global.name("false"))) {
return false;
}
throw new ConstructionException(Global.name("exception.boolean"));
}
static public boolean truecheck(String s) {
s = s.toLowerCase();
if (s.equals("true") || s.equals(Global.name("true"))) {
return true;
}
if (s.equals("false") || s.equals(Global.name("false"))) {
return true;
}
return false;
}
static public boolean test(final String f, final String tag, final String s) {
return f.equalsIgnoreCase(Global.name(tag + "." + s, ""))
|| f.equals(Global.name(tag + ".short." + s, ""))
|| f.equals(Global.name(tag + "." + s + ".short", ""))
|| f.equalsIgnoreCase(s);
}
static public int startTest(final String tag, final String s) {
int i = startTest0(Global.name(tag, tag).toLowerCase(), s.toLowerCase());
if (i > 0) {
return i;
}
i = startTest0(Global.name(tag + ".short", tag), s);
if (i > 0) {
return i;
}
return startTest0(tag, s.toLowerCase());
}
static public int startTest0(final String tag, final String s) {
if (s.startsWith(tag + " ")) {
return tag.length() + 1;
}
return -1;
}
static public boolean ptest(final String f, final String s) {
return test(f, "function", s);
}
static public boolean nametest(final String f, final String s) {
return test(f, "name", s);
}
/**
* Works like find, but can interpret c(k), p1(s), p2(s) etc.
*/
public String extend(String s) {
if (s.startsWith("c(") && s.endsWith(")")) {
s = s.substring(2, s.length() - 1);
final ConstructionObject o = C.find(s);
if (o instanceof PrimitiveCircleObject) {
return ((PrimitiveCircleObject) o).getP1().getName();
}
} else if (s.startsWith("a(") && s.endsWith(")")) {
s = s.substring(2, s.length() - 1);
final ConstructionObject o = C.find(s);
if (o instanceof TwoPointLineObject) {
return ((TwoPointLineObject) o).getP1().getName();
}
} else if (s.startsWith("b(") && s.endsWith(")")) {
s = s.substring(2, s.length() - 1);
final ConstructionObject o = C.find(s);
if (o instanceof TwoPointLineObject) {
return ((TwoPointLineObject) o).getP2().getName();
}
}
return s;
}
MacroRunner MR = new MacroRunner();
static ObjectConstructor OCs[] = { new PointConstructor(),
new SegmentConstructor(), new LineConstructor(),
new RayConstructor(), new CircleConstructor(),
new IntersectionConstructor(), new ParallelConstructor(),
new PlumbConstructor(), new MidpointConstructor(),
new AngleConstructor(), new AreaConstructor(),
new QuadricConstructor(), new ExpressionConstructor(),
new FunctionConstructor() };
static public String ONs[] = { "point", "segment", "line", "ray", "circle",
"intersection", "parallel", "plumb", "angle", "area",
"quadric", "expression", "function","text" };
static public int findFunction(final String function, final ZirkelCanvas zc) {
for (int i = 0; i < OCs.length; i++) {
if (nametest(function, OCs[i].getTag()) && zc.enabled(ONs[i])) {
return i;
}
}
return -1;
}
}

View file

@ -0,0 +1,29 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 <http://www.gnu.org/licenses/>.
*/
package rene.zirkel.construction;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.objects.ConstructionObject;
public interface Selector {
public boolean isAdmissible(ZirkelCanvas zc, ConstructionObject o);
}