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

View file

@ -0,0 +1,181 @@
/*
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.constructors;
// file: QuadricConstructor.java
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.zirkel.Zirkel;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.QuadricObject;
public class QuadricConstructor extends ObjectConstructor {
PointObject P[];
int NPoints;
static PointObject previewPoint = null;
static QuadricObject previewQuadric = null;
public static void deletePreview(final ZirkelCanvas zc) {
if (previewQuadric != null) {
zc.delete(previewQuadric);
previewPoint = null;
previewQuadric = null;
zc.reset();
}
}
private void arrangeP() {
if (NPoints < 5) {
P[4] = previewPoint;
for (int i = 3; i >= NPoints; i--) {
P[i] = P[0];
}
}
}
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual)
return;
if (previewPoint == null)
previewPoint = new PointObject(zc.getConstruction(), "PrevPoint");
if (previewQuadric != null)
previewQuadric.setHidden(true);
final PointObject p = zc.selectCreatePoint(e.getX(), e.getY());
if (previewQuadric != null)
previewQuadric.setHidden(false);
if (p != null) {
P[NPoints++] = p;
p.setSelected(true);
arrangeP();
if (previewQuadric == null) {
previewQuadric = new QuadricObject(zc.getConstruction(), P);
zc.addObject(previewQuadric);
}
previewQuadric.setDefaults();
zc.repaint();
}
showStatus(zc);
if (NPoints == 5) {
final QuadricObject Q = new QuadricObject(zc.getConstruction(), P);
zc.addObject(Q);
Q.setDefaults();
zc.clearSelected();
deletePreview(zc);
}
}
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
if (previewPoint != null) {
previewQuadric.validate();
previewPoint.move(zc.x(e.getX()), zc.y(e.getY()));
zc.repaint();
}
super.mouseMoved(e, zc, simple);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Zirkel.name("message.quadric") + " " + (NPoints + 1));
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P = new PointObject[5];
NPoints = 0;
showStatus(zc);
} else {
zc.setPrompt(Zirkel.name("prompt.quadric"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Quadric"))
return false;
final XmlTag tag = tree.getTag();
for (int i = 0; i < 5; i++)
if (!tag.hasParam("point" + (i + 1)))
throw new ConstructionException("Quadric points missing!");
try {
final PointObject P[] = new PointObject[5];
for (int i = 0; i < 5; i++)
P[i] = (PointObject) c.find(tag.getValue("point" + (i + 1)));
final QuadricObject p = new QuadricObject(c, P);
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Quadric points illegal!");
}
return true;
}
public String getPrompt() {
return Zirkel.name("prompt.quadric");
}
@Override
public String getTag() {
return "Quadric";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 5)
throw new ConstructionException(Zirkel.name("exception.nparams"));
final ConstructionObject P[] = new PointObject[5];
for (int i = 0; i < 5; i++) {
P[i] = c.find(params[i]);
if (P[i] == null)
throw new ConstructionException(Zirkel
.name("exception.notfound")
+ " " + params[i]);
if (!(P[i] instanceof PointObject))
throw new ConstructionException(Zirkel.name("exception.type")
+ " " + params[i]);
}
final QuadricObject s = new QuadricObject(c, (PointObject[]) P);
if (!name.equals(""))
s.setNameCheck(name);
c.add(s);
s.setDefaults();
}
}

BIN
rene/zirkel/constructors/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,448 @@
/*
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.constructors;
// file: Cicle3Constructor.java
import eric.JSelectPopup;
import java.awt.event.MouseEvent;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.AngleObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.FixedAngleObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
public class AngleConstructor extends ObjectConstructor {
PointObject P1 = null, P2 = null, P3 = null;
boolean Fixed = false;
public AngleConstructor(final boolean fixed) {
Fixed = fixed;
}
public AngleConstructor() {
this(false);
}
FixedAngleObject A;
ConstructionObject O;
boolean ShowsValue, Fix;
int Moved, ex, ey;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc){
if (!zc.Visual)
return;
Fix = e.isShiftDown() || Fixed;
ex = e.getX(); ey = e.getY();
ConstructionObject obj = null;
if(!Fix || !waitForLastPoint()){
obj = select(e.getX(), e.getY(), zc, e.isAltDown());
if(obj!=null){
setConstructionObject(obj, zc);
} else {
Dragging = false;
}
} else { //third clic for a fixed angle, obj=null but whatever
setConstructionObject(obj, zc);
}
}
@Override
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc) {
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(obj instanceof PointonObject)) {
int x=JSelectPopup.getMouseX();
int y=JSelectPopup.getMouseY();
PointObject o=new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), obj);
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
obj=o;
}
if(P1==null){
if(obj instanceof PointObject){
P1=(PointObject) obj;
P1.setSelected(true);
zc.repaint();
}
showStatus(zc);
} else if(P2==null){
if(obj instanceof PointObject){
P2=(PointObject) obj;
P2.setSelected(true);
zc.repaint();
}
showStatus(zc);
} else {
if(!Fix){
if(obj instanceof PointObject){
P3 = (PointObject) obj;
if(P3==P1 || P3==P2){
P3=null;
return;
}
final AngleObject a = new AngleObject(zc.getConstruction(), P1, P2, P3);
zc.addObject(a);
a.setDefaults();
if (P3.moveable() && !P3.isPointOn() && zc.isNewPoint()) {
ShowsValue = a.showValue();
if (Global.getParameter("options.movefixname", true))
a.setShowValue(true);
O = a;
Dragging = true;
a.validate();
zc.repaint();
} else {
Dragging = false;
//P1 = P2 = P3 = null;
reset(zc);
zc.validate();
zc.repaint();
}
}
} else {
final FixedAngleObject a = new FixedAngleObject(zc.getConstruction(), P1, P2, zc.x(ex), zc.y(ey));
zc.addObject(a);
a.setDefaults();
a.init(zc.getConstruction(), zc.x(ex), zc.y(ey));
Moved = 0;
Dragging = true;
ShowsValue = a.showValue();
if (Global.getParameter("options.movefixname", true))
a.setShowValue(true);
O = A = a;
P3 = null;
zc.repaint();
}
}
}
@Override
public boolean waitForLastPoint() {
return P1 != null && P2 != null;
}
@Override
public boolean waitForPoint() {
return !Fixed || (P1 == null || P2 == null);
}
@Override
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
if (!Fixed) {
P3 = select(e.getX(), e.getY(), zc, e.isAltDown());
if (P3 != null) {
final AngleObject a = new AngleObject(zc.getConstruction(), P1,
P2, P3);
zc.addObject(a);
a.setDefaults();
}
zc.repaint();
P3 = null;
} else {
final FixedAngleObject a = new FixedAngleObject(zc
.getConstruction(), P1, P2, zc.x(e.getX()), zc.y(e.getY()));
zc.addObject(a);
a.setDefaults();
a.init(zc.getConstruction(), zc.x(e.getX()), zc.y(e.getY()));
zc.setPreviewObject(a);
zc.repaint();
}
}
@Override
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging)
return;
Moved++;
if (P3 == null) {
A.init(zc.getConstruction(), zc.x(e.getX()), zc.y(e.getY()));
if (A instanceof FixedAngleObject)
((FixedAngleObject) A).setDragable(Moved > 5);
} else {
P3.move(zc.x(e.getX()), zc.y(e.getY()));
zc.validate();
}
zc.repaint();
}
@Override
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging)
return;
Dragging = false;
O.setShowValue(ShowsValue);
zc.repaint();
if (P3 == null) {
zc.clearSelected();
A.round();
if (Moved < 5) {
A.edit(zc, true, true);
if (A instanceof FixedAngleObject
&& ((FixedAngleObject) A).isEditAborted()) {
zc.delete(A);
reset(zc);
return;
}
}
A.validate();
} else
P3.updateText();
reset(zc);
zc.showStatus();
}
public PointObject select(final int x, final int y, final ZirkelCanvas zc, boolean altdown) {
return zc.selectCreatePoint(x, y, altdown);
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P1 = P2 = P3 = null;
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.angle"));
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (Fixed) {
if (P1 == null)
zc.showStatus(Global.name("message.fixedangle.first"));
else if (P2 == null)
zc.showStatus(Global.name("message.fixedangle.root"));
else
zc.showStatus(Global.name("message.fixedangle.second"));
} else {
if (P1 == null)
zc.showStatus(Global.name("message.angle.first"));
else if (P2 == null)
zc.showStatus(Global.name("message.angle.root"));
else
zc.showStatus(Global.name("message.angle.second"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Angle"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("first")) {
final AngleObject o = new AngleObject(c);
try {
if (tag.hasParam("display")) {
final String type = tag.getValue("display");
if (type.equals("small"))
o.setDisplaySize(AngleObject.SMALL);
if (type.equals("normalsize"))
o.setDisplaySize(AngleObject.NORMALSIZE);
if (type.equals("large"))
o.setDisplaySize(AngleObject.LARGE);
if (type.equals("larger"))
o.setDisplaySize(AngleObject.LARGER);
if (type.equals("rectangle"))
o.setDisplaySize(AngleObject.RECT);
}
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
if (tag.hasTrueParam("filled"))
o.setFilled(true);
if (tag.hasParam("fixed"))
o.setFixed(tag.getValue("fixed"));
if (tag.hasTrueParam("acute"))
o.setObtuse(false);
else
o.setObtuse(true);
} catch (final Exception e) {
}
}
if (!tag.hasParam("first") || !tag.hasParam("root"))
throw new ConstructionException("Angle parameters missing!");
if (tag.hasParam("second")) {
try {
final PointObject p1 = (PointObject) c.find(tag
.getValue("first"));
final PointObject p2 = (PointObject) c.find(tag
.getValue("root"));
final PointObject p3 = (PointObject) c.find(tag
.getValue("second"));
final AngleObject o = new AngleObject(c, p1, p2, p3);
if (tag.hasParam("display")) {
final String type = tag.getValue("display");
if (type.equals("small"))
o.setDisplaySize(AngleObject.SMALL);
if (type.equals("large"))
o.setDisplaySize(AngleObject.LARGE);
if (type.equals("larger"))
o.setDisplaySize(AngleObject.LARGER);
if (type.equals("rectangle"))
o.setDisplaySize(AngleObject.RECT);
}
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
if (tag.hasTrueParam("filled"))
o.setFilled(true);
if (tag.hasParam("fixed"))
o.setFixed(tag.getValue("fixed"));
if (tag.hasTrueParam("acute"))
o.setObtuse(false);
else
o.setObtuse(true);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Angle parameters illegal!");
}
} else {
try {
final PointObject p1 = (PointObject) c.find(tag
.getValue("first"));
final PointObject p2 = (PointObject) c.find(tag
.getValue("root"));
final FixedAngleObject o = new FixedAngleObject(c, p1, p2, 0, 0);
if (tag.hasParam("display")) {
final String type = tag.getValue("display");
if (type.equals("small"))
o.setDisplaySize(FixedAngleObject.SMALL);
if (type.equals("large"))
o.setDisplaySize(FixedAngleObject.LARGE);
if (type.equals("larger"))
o.setDisplaySize(FixedAngleObject.LARGER);
if (type.equals("rectangle"))
o.setDisplaySize(FixedAngleObject.RECT);
}
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
if (tag.hasTrueParam("filled"))
o.setFilled(true);
if (tag.hasTrueParam("acute"))
o.setObtuse(false);
else
o.setObtuse(true);
if (tag.hasTrueParam("inverse"))
o.setInverse(true);
else
o.setInverse(false);
if (tag.hasTrueParam("reduced"))
o.setReduced(true);
else
o.setReduced(false);
if (tag.hasTrueParam("dragable"))
o.setDragable(true);
if (tag.hasTrueParam("drawable"))
o.setDragable(true); // downward compatibility
if (tag.hasParam("fixed"))
o.setFixed(tag.getValue("fixed"));
else
throw new ConstructionException("");
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Angle parameters illegal!");
}
}
return true;
}
@Override
public String getTag() {
return "Angle";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 3)
throw new ConstructionException(Global.name("exception.nparams"));
final ConstructionObject P1 = c.find(params[0]);
if (P1 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[0]);
final ConstructionObject P2 = c.find(params[1]);
if (P2 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[1]);
final ConstructionObject P3 = c.find(params[2]);
if (P3 == null || !(P3 instanceof PointObject)) {
final Expression ex = new Expression(params[2], c, null);
if (!ex.isValid())
throw new ConstructionException(Global.name("exception.expression"));
final FixedAngleObject s = new FixedAngleObject(c,
(PointObject) P1, (PointObject) P2, 0, 0);
s.setFixed(params[2]);
if (!name.equals(""))
s.setNameCheck(name);
c.add(s);
s.setDefaults();
s.setObtuse(true);
s.setFixed(params[2]);
s.validate();
return;
}
if (!(P1 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[0]);
if (!(P2 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[1]);
if (!(P3 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[2]);
if (P1 == P2 || P2 == P3)
throw new ConstructionException(Global.name("exception.parameter"));
final AngleObject s = new AngleObject(c, (PointObject) P1,
(PointObject) P2, (PointObject) P3);
if (!name.equals(""))
s.setNameCheck(name);
c.add(s);
s.setDefaults();
}
}

View file

@ -0,0 +1,239 @@
/*
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.constructors;
// file: PointConstructor.java
import eric.JSelectPopup;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.Vector;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.AreaObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
public class AreaConstructor extends ObjectConstructor {
AreaObject Polygon=null;
PointObject PreviewPoint=null;
boolean newPoint = false;
public static void deletePreview(final ZirkelCanvas zc) {
zc.reset();
}
public void deletePolygon(ZirkelCanvas zc) {
if (Polygon!=null) {
// Suppression et réinitialisation :
zc.delete(Polygon);
Polygon=null;
zc.clearSelected();
}
}
public void validPolygon(ZirkelCanvas zc) {
if (Polygon!=null) {
Polygon.clearPreviewPoint();
Polygon.setIndicated(false);
zc.update_distant(Polygon, 1);
Polygon=null;
zc.clearSelected();
}
}
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
final PointObject P = zc.selectCreatePoint(e.getX(), e.getY(), e.isAltDown());
newPoint = newPoint || zc.isNewPoint();
setConstructionObject(P, zc);
}
@Override
public void setConstructionObject(ConstructionObject P, ZirkelCanvas zc) {
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(P instanceof PointonObject)) {
int x=JSelectPopup.getMouseX();
int y=JSelectPopup.getMouseY();
PointObject o=new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), P);
newPoint = true;
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
P=o;
}
if (P!=null) {
if (Polygon==null) {
// Création et mise en forme de l'objet polygone :
Polygon=new AreaObject(zc.getConstruction(), new Vector());
zc.addObject(Polygon);
Polygon.setDefaults();
if (!Polygon.isSolid()) {
Polygon.setBack(true);
}
// Création du point preview (sommet n+1) :
PreviewPoint=new PointObject(zc.getConstruction(), "PrevPoint");
PreviewPoint.setXY(P.getX(), P.getY());
Polygon.setPreviewPoint(PreviewPoint);
}
P.setSelected(true);
final Enumeration en=Polygon.V.elements();
while (en.hasMoreElements()) {
// Si on "referme" le polygone en cliquant sur l'un des points existants :
if (en.nextElement()==P) {
// Et si le nombre de sommets est inférieur à 3, cela s'apparente à
// une annulation :
if (Polygon.V.size()<3) {
deletePolygon(zc);
} else {
// Si on a créé un sommet à la volée, il faut réorganiser
// pour éviter un pb de dépendance
if(newPoint){
System.out.println("new point !");
zc.getConstruction().reorderConstruction();
zc.reloadCD();
newPoint = false;
}
validPolygon(zc);
}
// de toutes façons, on quitte :
return;
}
}
Polygon.V.addElement(P);
zc.validate();
zc.repaint();
}
}
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
PointObject p=zc.indicateCreatePoint(e.getX(), e.getY(), false);
if (Polygon!=null) {
if ((p==null)) {
PreviewPoint.move(zc.x(e.getX()), zc.y(e.getY()));
} else {
PreviewPoint.move(p.getX(), p.getY());
}
Polygon.validate();
Polygon.setDefaults();
Polygon.setIndicated(true);
zc.repaint();
}
}
@Override
public String getTag() {
return "Polygon";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams<3) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final Vector v=new Vector();
for (int i=0; i<nparams; i++) {
final ConstructionObject o=c.find(params[i]);
if (o==null) {
throw new ConstructionException(Global.name("exception.notfound")
+" "+params[i]);
}
if (!(o instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")
+" "+params[i]);
}
v.addElement(o);
}
final AreaObject o=new AreaObject(c, v);
if (!name.equals("")) {
o.setNameCheck(name);
}
c.add(o);
o.setDefaults();
o.setBack(true);
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Polygon")) {
return false;
}
final XmlTag tag=tree.getTag();
try {
int i=1;
final Vector v=new Vector();
while (true) {
final PointObject p=(PointObject) c.find(tag.getValue("point"
+i));
if (p==null) {
break;
}
v.addElement(p);
i++;
}
final AreaObject o=new AreaObject(c, v);
o.setBack(true);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
if (tag.hasParam("filled")) {
o.setFilled(false);
}
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Polygon parameters illegal!");
}
return true;
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.area"));
zc.setPrompt("="+Global.name("prompt.area"));
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
deletePolygon(zc);
zc.showStatus(Global.name("message.area"));
}
}

View file

@ -0,0 +1,244 @@
/*
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.constructors;
// file: PointConstructor.java
import java.util.ArrayList;
import java.util.Enumeration;
import java.awt.event.MouseEvent;
import eric.GUI.palette.PaletteManager;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.construction.Selector;
import rene.zirkel.objects.AreaObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.InsideObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
import rene.zirkel.objects.TwoPointLineObject;
public class BoundedPointConstructor extends ObjectConstructor implements
Selector {
boolean Control;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
Control=e.isControlDown();
final ConstructionObject o=zc.selectWithSelector(e.getX(), e.getY(),
this);
if (o==null) {
return;
}
final PointObject p=new PointObject(zc.getConstruction(), zc.x(e.getX()), zc.y(e.getY()), o);
if (!e.isShiftDown()) {
p.setUseAlpha(true);
}
// if (Control && o instanceof InsideObject) p.setInside(true);
if (o instanceof InsideObject) {
p.setInside(true);
}
if (zc.is3D()) { //Dibs : 2D -> 3D.
zc.validate(); //Dibs
if (((PointObject) p).getBound() instanceof AreaObject) {
AreaObject surface= (AreaObject) ((PointObject) p).getBound();
if (((AreaObject)surface).V.size()>2&&((PointObject) surface.V.get(0)).is3D()&&((PointObject) surface.V.get(1)).is3D()&&((PointObject) surface.V.get(2)).is3D()) {
try {
double x0=((PointObject) surface.V.get(0)).getX3D();
double y0=((PointObject) surface.V.get(0)).getY3D();
double z0=((PointObject) surface.V.get(0)).getZ3D();
double x1=((PointObject) surface.V.get(1)).getX3D();
double y1=((PointObject) surface.V.get(1)).getY3D();
double z1=((PointObject) surface.V.get(1)).getZ3D();
double x2=((PointObject) surface.V.get(2)).getX3D();
double y2=((PointObject) surface.V.get(2)).getY3D();
double z2=((PointObject) surface.V.get(2)).getZ3D();
double x_O=zc.getConstruction().find("O").getX();
double x_X=zc.getConstruction().find("X").getX();
double x_Y=zc.getConstruction().find("Y").getX();
double x_Z=zc.getConstruction().find("Z").getX();
double y_O=zc.getConstruction().find("O").getY();
double y_X=zc.getConstruction().find("X").getY();
double y_Y=zc.getConstruction().find("Y").getY();
double y_Z=zc.getConstruction().find("Z").getY();
double coeffa=(x1-x0)*(x_X-x_O)+(y1-y0)*(x_Y-x_O)+(z1-z0)*(x_Z-x_O);
double coeffb=(x2-x0)*(x_X-x_O)+(y2-y0)*(x_Y-x_O)+(z2-z0)*(x_Z-x_O);
double coeffc=(x1-x0)*(y_X-y_O)+(y1-y0)*(y_Y-y_O)+(z1-z0)*(y_Z-y_O);
double coeffd=(x2-x0)*(y_X-y_O)+(y2-y0)*(y_Y-y_O)+(z2-z0)*(y_Z-y_O);
double coeffe=p.getX()-x_O-x0*(x_X-x_O)-y0*(x_Y-x_O)-z0*(x_Z-x_O);
double coefff=p.getY()-y_O-x0*(y_X-y_O)-y0*(y_Y-y_O)-z0*(y_Z-y_O);
double alpha1=(coeffe*coeffd-coefff*coeffb)/(coeffa*coeffd-coeffb*coeffc);
double beta1=(coeffa*coefff-coeffc*coeffe)/(coeffa*coeffd-coeffb*coeffc);
((PointObject) p).setX3D(x0+alpha1*(x1-x0)+beta1*(x2-x0));
((PointObject) p).setY3D(y0+alpha1*(y1-y0)+beta1*(y2-y0));
((PointObject) p).setZ3D(z0+alpha1*(z1-z0)+beta1*(z2-z0));
((PointObject) p).setIs3D(true);
p.validate();
} catch (final Exception eBary) {
}
}
}
}
zc.addObject(p);
p.validate();
p.setDefaults();
}
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
Control=e.isControlDown();
zc.indicateWithSelector(e.getX(), e.getY(), this);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.boundedpoint",
"Bounded Point: Choose a circle or line!"));
}
public boolean isAdmissible(final ZirkelCanvas zc,
final ConstructionObject o) {
// if (Control && o instanceof InsideObject) return true;
// else if (!Control && o instanceof PointonObject) return true;
if (o instanceof InsideObject) {
return true;
}
return false;
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "PointOn")) {
return false;
}
final XmlTag tag=tree.getTag();
if (!tag.hasParam("on")) {
throw new ConstructionException("Point bound missing!");
}
try {
final ConstructionObject o=(ConstructionObject) c.find(tag.getValue("on"));
if (o!=null&&!(o instanceof PointonObject)&&!(o instanceof InsideObject)) {
throw new ConstructionException("");
}
double x=0, y=0;
double x3D=0, y3D=0, z3D=0;
try {
x=new Double(tag.getValue("x")).doubleValue();
y=new Double(tag.getValue("y")).doubleValue();
} catch (final Exception e) {
}
try {
x3D=new Double(tag.getValue("x3D")).doubleValue();
y3D=new Double(tag.getValue("y3D")).doubleValue();
z3D=new Double(tag.getValue("z3D")).doubleValue();
} catch (final Exception e) {
}
PointObject p;
if (o!=null) {
p=new PointObject(c, x, y, o);
} else {
p=new PointObject(c, x, y);
p.setLaterBind(tag.getValue("on"));
}
p.setInside(tag.hasTrueParam("inside"));
try {
final double alpha=new Double(tag.getValue("alpha")).doubleValue();
p.setAlpha(alpha);
p.setUseAlpha(true);
if (tag.hasParam("on")) {
final ConstructionObject on=c.find(tag.getValue("on"));
if (on!=null) {
p.project(on, alpha);
}
}
} catch (final Exception e) {
}
if (tag.hasParam("shape")) {
final String s=tag.getValue("shape");
if (s.equals("square")) {
p.setType(0);
}
if (s.equals("diamond")) {
p.setType(1);
}
if (s.equals("circle")) {
p.setType(2);
}
if (s.equals("dot")) {
p.setType(3);
}
if (s.equals("cross")) {
p.setType(4);
}
if (s.equals("dcross")) {
p.setType(5);
}
}
if (tag.hasParam("boundorder")) {
p.setBoundOrder(Double.valueOf(tag.getValue("boundorder")).doubleValue());
}
if (tag.hasParam("is3D")) {
p.setIs3D(true);
p.move3D(x3D,y3D,z3D);
p.move(c.find("O").getX()+x3D*(c.find("X").getX()-c.find("O").getX())+y3D*(c.find("Y").getX()-c.find("O").getX())+z3D*(c.find("Z").getX()-c.find("O").getX()), c.find("O").getY()+x3D*(c.find("X").getY()-c.find("O").getY())+y3D*(c.find("Y").getY()-c.find("O").getY())+z3D*(c.find("Z").getY()-c.find("O").getY()));
}
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
if (tag.hasParam("fixed")) {
p.setFixed(tag.getValue("x"), tag.getValue("y"));
}
if (tag.hasParam("increment")) {
try {
p.setIncrement(new Double(tag.getValue("increment")).doubleValue());
} catch (final Exception e) {
}
}
} catch (final Exception e) {
e.printStackTrace();
throw new ConstructionException("Illegal point bound!");
}
return true;
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
zc.setPrompt(Global.name("prompt.pointon"));
}
}

View file

@ -0,0 +1,150 @@
/*
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.constructors;
// file: Cicle3Constructor.java
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.Circle3Object;
import rene.zirkel.objects.PointObject;
public class Circle3Constructor extends ObjectConstructor {
PointObject P1 = null, P2 = null, P3 = null;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual)
return;
if (P1 == null) {
P1 = select(e.getX(), e.getY(), zc, e.isAltDown());
if (P1 != null) {
P1.setSelected(true);
zc.repaint();
}
showStatus(zc);
} else if (P2 == null) {
P2 = select(e.getX(), e.getY(), zc, e.isAltDown());
if (P2 != null && P2 != P1) {
P2.setSelected(true);
zc.repaint();
}
showStatus(zc);
} else {
P3 = select(e.getX(), e.getY(), zc, e.isAltDown());
if (P3 != null) {
final Circle3Object c = new Circle3Object(zc.getConstruction(),
P1, P2, P3);
zc.addObject(c);
c.setDefaults();
c.updateCircleDep();
P1 = P2 = P3 = null;
zc.clearSelected();
showStatus(zc);
}
}
}
@Override
public boolean waitForLastPoint() {
return P1 != null && P2 != null;
}
@Override
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
P3 = select(e.getX(), e.getY(), zc, e.isAltDown());
if (P3 != null) {
final Circle3Object c = new Circle3Object(zc.getConstruction(), P1,
P2, P3);
zc.addObject(c);
c.setDefaults();
zc.validate();
zc.repaint();
P3 = null;
}
}
public PointObject select(final int x, final int y, final ZirkelCanvas zc, boolean altdown) {
return zc.selectCreatePoint(x, y, altdown);
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P1 = P2 = P3 = null;
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.circle3"));
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1 == null)
zc.showStatus(Global.name("message.circle3.first",
"Circle: Choose the first radius point!"));
else if (P2 == null)
zc.showStatus(Global.name("message.circle3.second",
"Circle: Choose the second radius point!"));
else
zc.showStatus(Global.name("message.circle3.midpoint",
"Circle: Choose the midpoint!"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Circle3"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("midpoint") || !tag.hasParam("from")
|| !tag.hasParam("to"))
throw new ConstructionException("Circle3 parameters missing!");
try {
final PointObject p1 = (PointObject) c.find(tag
.getValue("midpoint"));
final PointObject p2 = (PointObject) c.find(tag.getValue("from"));
final PointObject p3 = (PointObject) c.find(tag.getValue("to"));
final Circle3Object o = new Circle3Object(c, p2, p3, p1);
if (tag.hasParam("partial"))
o.setPartial(true);
if (tag.hasParam("start") && tag.hasParam("end"))
o.setRange(tag.getValue("start"), tag.getValue("end"));
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Circle3 parameters illegal!");
}
return true;
}
}

View file

@ -0,0 +1,448 @@
/*
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.constructors;
// file: PointConstructor.java
import eric.JSelectPopup;
import java.awt.event.MouseEvent;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.macro.Macro;
import rene.zirkel.objects.Circle3Object;
import rene.zirkel.objects.CircleObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.FixedCircleObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
import rene.zirkel.objects.PrimitiveCircleObject;
import rene.zirkel.objects.SegmentObject;
public class CircleConstructor extends ObjectConstructor {
PointObject P1=null, P2=null;
boolean Fixed=false;
boolean reallyFixed=false;
int EventX, EventY;
public CircleConstructor(final boolean fixed) {
Fixed=fixed;
}
public CircleConstructor() {
this(false);
}
FixedCircleObject C;
ConstructionObject O;
boolean ShowsValue, ShowsName;
int Moved;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
ConstructionObject obj=null;
reallyFixed=(e.isShiftDown()||Fixed);
EventX=e.getX();
EventY=e.getY();
if ((P1==null)||(!reallyFixed&&(P2==null))){
obj=select(e.getX(), e.getY(), zc, e.isAltDown());
}
setConstructionObject(obj, zc);
}
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc) {
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(obj instanceof PointonObject)) {
int x=JSelectPopup.getMouseX();
int y=JSelectPopup.getMouseY();
PointObject o=new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), obj);
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
obj=o;
}
if (P1==null) {
if (obj instanceof PointObject) {
P1=(PointObject) obj;
P1.setSelected(true);
zc.repaint();
}
} else {
if (reallyFixed) {
final FixedCircleObject c=new FixedCircleObject(zc.getConstruction(), P1, zc.x(EventX), zc.y(EventY));
zc.addObject(c);
c.setDefaults();
zc.repaint();
O=C=c;
ShowsValue=c.showValue();
ShowsName=c.showName();
if (Global.getParameter("options.movefixname", true)) {
C.setShowValue(true);
C.setShowName(true);
}
Dragging=true;
Moved=0;
P2=null;
} else {
if (obj instanceof PointObject) {
P2=(PointObject) obj;
if (P2==P1) {
P2=null;
return;
}
final CircleObject c=new CircleObject(zc.getConstruction(), P1, P2);
zc.addObject(c);
c.setDefaults();
c.validate();
zc.repaint();
if (P2.moveable()&&!P2.isPointOn()&&zc.isNewPoint()) {
ShowsValue=c.showValue();
ShowsName=c.showName();
if (Global.getParameter("options.movename", false)) {
c.setShowValue(true);
c.setShowName(true);
}
O=c;
Dragging=true;
Moved=0;
} else {
P1.setSelected(false);
P1=P2=null;
}
}
}
}
showStatus(zc);
}
@Override
public boolean waitForLastPoint() {
return P1!=null&&P2==null;
}
@Override
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
P2=select(e.getX(), e.getY(), zc, e.isAltDown());
if (P2!=null) {
final CircleObject c=new CircleObject(zc.getConstruction(), P1,
P2);
zc.addObject(c);
c.setDefaults();
c.validate();
zc.repaint();
}
P2=null;
}
@Override
public boolean waitForPoint() {
return P1==null||!Fixed;
}
@Override
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
}
Moved++;
if (P2==null) {
C.init(zc.getConstruction(), zc.x(e.getX()), zc.y(e.getY()));
if (C instanceof FixedCircleObject) {
((FixedCircleObject) C).setDragable(Moved>5);
}
} else {
P2.move(zc.x(e.getX()), zc.y(e.getY()));
zc.validate();
}
zc.repaint();
}
@Override
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
}
Dragging=false;
O.setShowValue(ShowsValue);
O.setShowName(ShowsName);
zc.repaint();
if (P2==null) {
P1.setSelected(false);
P1=null;
C.round();
if (Moved<=5) {
C.edit(zc, true, true);
if (C instanceof FixedCircleObject
&&((FixedCircleObject) C).isEditAborted()) {
zc.delete(C);
zc.repaint();
reset(zc);
}
}
C.validate();
} else {
P1.setSelected(false);
P2.updateText();
P1=P2=null;
}
O.updateCircleDep();
zc.repaint();
zc.showStatus();
}
public PointObject select(final int x, final int y, final ZirkelCanvas zc, boolean altdown) {
return zc.selectCreatePoint(x, y, altdown);
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P1=P2=null;
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.circle"));
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (Fixed) {
if (P1==null) {
zc.showStatus(Global.name("message.fixedcircle.midpoint"));
} else {
zc.showStatus(Global.name("message.fixedcircle.radius"));
}
} else {
if (P1==null) {
zc.showStatus(Global.name("message.circle.midpoint"));
} else {
zc.showStatus(Global.name("message.circle.radius"));
}
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Circle")) {
return false;
}
final XmlTag tag=tree.getTag();
try {
if (!tag.hasParam("midpoint")) {
throw new ConstructionException("Circle parameters missing!");
}
if (!tag.hasParam("through")) {
if (tag.hasParam("fixed")) {
final PointObject p1=(PointObject) c.find(tag.getValue("midpoint"));
final FixedCircleObject o=new FixedCircleObject(c, p1, 0,
0);
c.add(o);
setConditionals(tree, c, o);
setName(tag, o);
set(tree, o);
if (tag.hasParam("partial")) {
o.setPartial(true);
}
if (tag.hasParam("filled")) {
o.setFilled(true);
}
if (tag.hasTrueParam("dragable")) {
o.setDragable(true);
}
if (tag.hasTrueParam("drawable")) {
o.setDragable(true); // downward compatibility
}
o.setFixed(tag.getValue("fixed"));
if (tag.hasParam("start")&&tag.hasParam("end")) {
o.setRange(tag.getValue("start"), tag.getValue("end"));
}
if (tag.hasParam("acute")) {
o.setObtuse(false);
}
if (tag.hasParam("chord")) {
o.setArc(false);
}
} else {
if (!(c instanceof Macro)) {
throw new ConstructionException(
"Circle parameters missing!");
}
final PointObject p1=(PointObject) c.find(tag.getValue("midpoint"));
final PrimitiveCircleObject o=new PrimitiveCircleObject(
c, p1);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
}
} else {
final PointObject p1=(PointObject) c.find(tag.getValue("midpoint"));
final PointObject p2=(PointObject) c.find(tag.getValue("through"));
final CircleObject o=new CircleObject(c, p1, p2);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
if (tag.hasParam("partial")) {
o.setPartial(true);
}
if (tag.hasParam("filled")) {
o.setFilled(true);
}
if (tag.hasParam("start")&&tag.hasParam("end")) {
o.setRange(tag.getValue("start"), tag.getValue("end"));
}
if (tag.hasParam("acute")) {
o.setObtuse(false);
}
if (tag.hasParam("chord")) {
o.setArc(false);
}
if (tag.hasParam("fixed")) {
try {
o.setFixed(true, tag.getValue("fixed"));
} catch (final Exception e) {
throw new ConstructionException("Fixed value illegal!");
}
}
}
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Circle parameters illegal!");
}
return true;
}
@Override
public String getTag() {
return "Circle";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams>3||nparams==0) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject P1=c.find(params[0]);
if (P1==null) {
throw new ConstructionException(Global.name("exception.notfound")
+" "+params[0]);
}
if (!(P1 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "
+params[0]);
}
if (nparams==1) {
final PrimitiveCircleObject s=new PrimitiveCircleObject(c,
(PointObject) P1);
c.add(s);
s.setDefaults();
if (!name.equals("")) {
s.setNameCheck(name);
}
return;
}
final ConstructionObject P2=c.find(params[1]);
if (P2==null) {
final Expression ex=new Expression(params[1], c, null);
if (!ex.isValid()) {
throw new ConstructionException(Global.name("exception.expression"));
}
final FixedCircleObject s=new FixedCircleObject(c,
(PointObject) P1, 0, 0);
c.add(s);
s.setDefaults();
s.setFixed(params[1]);
s.validate();
if (!name.equals("")) {
s.setNameCheck(name);
}
return;
}
if (P2 instanceof SegmentObject) {
final Circle3Object s=new Circle3Object(c, ((SegmentObject) P2).getP1(), ((SegmentObject) P2).getP2(), (PointObject) P1);
c.add(s);
s.setDefaults();
if (!name.equals("")) {
s.setNameCheck(name);
}
return;
}
if (!(P2 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "
+params[1]);
}
if (nparams==3) {
final ConstructionObject P3=c.find(params[2]);
if (P3==null||!(P3 instanceof PointObject)) {
final CircleObject s=new CircleObject(c, (PointObject) P1,
(PointObject) P2);
if (!s.canFix()) {
throw new ConstructionException(Global.name("exception.canfix"));
}
s.setFixed(true, params[2]);
if (!s.isValidFix()) {
throw new ConstructionException(Global.name("exception.fix")
+" "+params[2]);
}
c.add(s);
s.validate();
if (!name.equals("")) {
s.setNameCheck(name);
}
s.setDefaults();
return;
} else {
final Circle3Object cr=new Circle3Object(c, (PointObject) P2,
(PointObject) P3, (PointObject) P1);
c.add(cr);
cr.setDefaults();
if (!name.equals("")) {
cr.setNameCheck(name);
}
return;
}
}
final CircleObject s=new CircleObject(c, (PointObject) P1,
(PointObject) P2);
c.add(s);
s.setDefaults();
if (!name.equals("")) {
s.setName(name);
}
}
}

View file

@ -0,0 +1,57 @@
/*
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.constructors;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.EquationXYObject;
/**
*
* @author erichake
*/
public class EquationXYConstructor extends ObjectConstructor {
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "EqXY")) {
return false;
}
final XmlTag tag = tree.getTag();
if (tag.hasParam("f")) // function
{
final EquationXYObject eq = new EquationXYObject(c, tag
.getValue("f"), Integer.parseInt(tag.getValue("Dhor")));
eq.setName(tag.getValue("name"));
// eq.setDefaults();
set(tree, eq);
c.add(eq);
eq.updateText();
setConditionals(tree,c,eq);
}
return true;
}
}

View file

@ -0,0 +1,155 @@
/*
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.constructors;
// file: PointConstructor.java
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.ExpressionObject;
public class ExpressionConstructor extends ObjectConstructor {
ExpressionObject O;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
final double x = zc.x(e.getX()), y = zc.y(e.getY());
final ExpressionObject o = new ExpressionObject(zc.getConstruction(),
x, y);
zc.addObject(o);
o.setShowName(false);
o.setDefaults();
zc.repaint();
Dragging = true;
O = o;
}
@Override
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging)
return;
O.move(zc.x(e.getX()), zc.y(e.getY()));
zc.repaint();
}
@Override
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging)
return;
Dragging = false;
O.edit(zc, true, true);
}
@Override
public boolean waitForPoint() {
return false;
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.expression",
"Expression: Choose a place!"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Expression"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("x") || !tag.hasParam("y"))
throw new ConstructionException("Expression coordinates missing!");
if (!tag.hasParam("value"))
throw new ConstructionException(Global.name("exception.expression"));
final ExpressionObject p = new ExpressionObject(c, 0, 0);
double x, y;
try {
x = new Expression(tag.getValue("x"), c, p).getValue();
y = new Expression(tag.getValue("y"), c, p).getValue();
p.move(x, y);
} catch (final Exception e) {
}
p.setDefaults();
if (tag.hasParam("prompt"))
p.setPrompt(tag.getValue("prompt"));
if (tag.hasParam("fixed")) {
p.setFixed(tag.getValue("x"), tag.getValue("y"));
}
p.setShowValue(tag.hasParam("showvalue"));
setName(tag, p);
set(tree, p);
c.add(p);
try {
p.setExpression(tag.getValue("value"), c);
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.expression"));
}
setConditionals(tree, c, p);
if (tag.hasTrueParam("slider")) {
try {
p.setSlider(tag.getValue("min"), tag.getValue("max"));
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.expression"));
}
}
return true;
}
@Override
public String getTag() {
return "Expression";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams == 1) {
final ExpressionObject o = new ExpressionObject(c, c.getX()
+ (Math.random() - 0.5) * c.getW(), c.getY()
+ (Math.random() - 0.5) * c.getW());
if (!name.equals(""))
o.setNameCheck(name);
c.add(o);
o.setDefaults();
try {
o.setExpression(params[0], c);
} catch (final Exception e) {
throw new ConstructionException(Global.name("exception.expression"));
}
} else
throw new ConstructionException(Global.name("exception.nparams"));
}
@Override
public boolean useSmartBoard() {
return false;
}
}

View file

@ -0,0 +1,174 @@
/*
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.constructors;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.FunctionObject;
import rene.zirkel.objects.UserFunctionObject;
public class FunctionConstructor extends ObjectConstructor {
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Function")) {
return false;
}
final XmlTag tag = tree.getTag();
if (tag.hasParam("f")) {// function
if (!tag.hasParam("var")) {
throw new ConstructionException("Function invalid!");
}
try {
final String y = tag.getValue("f");
final String var = tag.getValue("var");
final UserFunctionObject f = new UserFunctionObject(c);
f.setDefaults();
setName(tag, f);
set(tree, f);
c.add(f);
double xpos, ypos;
try {
if (tag.hasParam("fixed")) {
f.setFixed(tag.getValue("x"), tag.getValue("y"));
} else {
xpos = new Expression(tag.getValue("x"), c, f)
.getValue();
ypos = new Expression(tag.getValue("y"), c, f)
.getValue();
f.move(xpos, ypos);
}
} catch (final Exception e) {
}
if (tag.hasParam("filled")) {
f.setFilled(true);
}
f.setExpressions(var, y);
setConditionals(tree, c, f);
f.updateText();
return true;
} catch (final Exception e) {
throw new ConstructionException("Function invalid!");
}
} else { // curve
if (!tag.hasParam("min") && !tag.hasParam("max")
&& !tag.hasParam("d") && !tag.hasParam("var")
&& !tag.hasParam("x") && !tag.hasParam("y")) {
throw new ConstructionException("Function invalid!");
}
try {
final String x = tag.getValue("x");
final String y = tag.getValue("y");
final String var = tag.getValue("var");
final String d = tag.getValue("d");
final String min = tag.getValue("min");
final String max = tag.getValue("max");
final FunctionObject f = new FunctionObject(c);
f.setDefaults();
setType(tag, f);
setName(tag, f);
set(tree, f);
c.add(f);
if (tag.hasParam("filled")) {
f.setFilled(true);
} else {
f.setFilled(false);
}
f.setExpressions(var, x, y);
f.setRange(min, max, d);
f.setSpecial(tag.hasTrueParam("special"));
if(tag.hasParam("minbound")) {
f.setMinOpen(tag.getValue("minbound").equals("0"));
f.setMinClosed(tag.getValue("minbound").equals("1"));
}
if(tag.hasParam("maxbound")) {
f.setMaxOpen(tag.getValue("maxbound").equals("0"));
f.setMaxClosed(tag.getValue("maxbound").equals("1"));
}
setConditionals(tree, c, f);
if (tag.hasParam("center")) {
f.setCenter(tag.getValue("center"));
}
f.updateText();
return true;
} catch (final Exception e) {
throw new ConstructionException("Function invalid!");
}
}
}
static public void setType(final XmlTag tag, final FunctionObject p) {
if (tag.hasParam("shape")) {
final String s = tag.getValue("shape");
if (s.equals("square"))
p.setType(0);
if (s.equals("diamond"))
p.setType(1);
if (s.equals("circle"))
p.setType(2);
if (s.equals("dot"))
p.setType(3);
if (s.equals("cross"))
p.setType(4);
if (s.equals("dcross"))
p.setType(5);
}
}
@Override
public String getTag() {
return "Function";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 6)
throw new ConstructionException(Global.name("exception.nparams"));
boolean added = false;
try {
final FunctionObject F = new FunctionObject(c);
c.add(F);
added = true;
if (!name.equals(""))
F.setNameCheck(name);
F.setRange(params[0], params[1], params[2]);
F.setExpressions(params[3], params[4], params[5]);
F.setDefaults();
} catch (final ConstructionException e) {
if (added)
c.back();
throw e;
} catch (final Exception e) {
if (added)
c.back();
throw new ConstructionException("Function Invalid!");
}
}
}

View file

@ -0,0 +1,140 @@
/*
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.constructors;
import eric.JZirkelCanvas;
import eric.Media;
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.ImageObject;
import rene.zirkel.objects.PointObject;
public class ImageConstructor extends ObjectConstructor {
PointObject P[];
int NPoints;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual)
return;
final PointObject p = zc.selectCreatePoint(e.getX(), e.getY(), e.isAltDown());
if (p != null) {
P[NPoints++] = p;
p.setSelected(true);
zc.repaint();
}
showStatus(zc);
if (NPoints == 3) {
final String filename = zc.loadImage();
if (filename.equals("")) {
reset(zc);
return;
}
Media.createMedia(filename);
final ImageObject o = new ImageObject(zc.getConstruction(), P,
filename);
zc.addObject(o);
zc.clearSelected();
reset(zc);
zc.repaint();
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (NPoints <= 1)
zc.showStatus(ConstructionObject.text1(
Global.name("message.image"), "" + (NPoints + 1)));
else
zc.showStatus(Global.name("message.image.last"));
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P = new PointObject[3];
NPoints = 0;
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.image"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Image"))
return false;
final XmlTag tag = tree.getTag();
for (int i = 0; i < 3; i++)
if (!tag.hasParam("point" + (i + 1)))
throw new ConstructionException("Image points missing!");
if (!tag.hasParam("filename"))
throw new ConstructionException("Image filename missing!");
try {
final PointObject P[] = new PointObject[3];
for (int i = 0; i < 3; i++)
P[i] = (PointObject) c.find(tag.getValue("point" + (i + 1)));
final String filename = JZirkelCanvas.getFilePath(c)+tag.getValue("filename");
Media.createMedia(filename);
final ImageObject p = new ImageObject(c, P, filename);
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Image points illegal!");
}
return true;
}
public String getPrompt() {
return Global.name("prompt.image");
}
@Override
public String getTag() {
return "Image";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
}
}

View file

@ -0,0 +1,468 @@
/*
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.constructors;
import java.awt.event.MouseEvent;
import eric.JZirkelCanvas;
import rene.util.MyVector;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.CircleIntersectionObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.IntersectionObject;
import rene.zirkel.objects.LineCircleIntersectionObject;
import rene.zirkel.objects.LineIntersectionObject;
import rene.zirkel.objects.LineQuadricIntersectionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObjectIntersectionObject;
import rene.zirkel.objects.PrimitiveCircleObject;
import rene.zirkel.objects.PrimitiveLineObject;
import rene.zirkel.objects.QuadricObject;
import rene.zirkel.objects.QuadricQuadricIntersectionObject;
public class IntersectionConstructor extends ObjectConstructor {
ConstructionObject P1=null, P2=null;
boolean immediate = false;
MouseEvent ev = null;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
ev = e;
if (P1==null) {
final MyVector v=zc.selectPointonObjects(e.getX(), e.getY());
if (v.size()==2) {
P1=(ConstructionObject) v.elementAt(0);
P2=(ConstructionObject) v.elementAt(1);
if (P1.equals(P2)|| P2.equals(P1) || (P1.isFilled()&&P2.isFilled())) {
P1=P2=null;
} else {
immediate=true;
}
}
}
ConstructionObject obj = null;
if(P1==null || P2==null){
obj = select(e.getX(), e.getY(), zc);
}
setConstructionObject(obj, zc);
}
@Override
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc){
if (P1==null) {
P1 = obj;
if (P1!=null) {
P1.setSelected(true);
zc.repaint();
showStatus(zc);
}
} else if(P2==null) {
P2 = obj;
}
if (P2!=null) {
if (P2==P1) {
P2=null;
return;
}
final IntersectionObject o[]=construct(P1, P2, zc.getConstruction());
if (o!=null) {
IntersectionObject oc=null;
if (immediate&&o.length>1) {
if (o[1].nearto(ev.getX(), ev.getY(), zc)) {
o[0]=null;
oc=o[1];
} else {
o[1]=null;
oc=o[0];
}
}
for (final IntersectionObject element : o) {
if (element!=null) {
element.setDefaults();
zc.addObject(element);
element.validate(zc.x(ev.getX()), zc.y(ev.getY()));
}
}
/**
* See, if the other intersection is visible and already a
* point of both objects.
*/
if (oc!=null) {
oc.autoAway();
}
}
reset(zc);
}
}
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
// System.out.println("inter : "+e.getX()+" "+e.getY());
zc.indicateIntersectedObjects(e.getX(), e.getY());
}
public static IntersectionObject[] construct(final ConstructionObject P1,
final ConstructionObject P2, final Construction c) {
IntersectionObject o[]=null;
if (P1 instanceof PrimitiveLineObject) {
if (P2 instanceof PrimitiveLineObject) {
o=new IntersectionObject[1];
o[0]=new LineIntersectionObject(c, (PrimitiveLineObject) P1,
(PrimitiveLineObject) P2);
} else if (P2 instanceof PrimitiveCircleObject) {
o=new IntersectionObject[2];
o[0]=new LineCircleIntersectionObject(c,
(PrimitiveLineObject) P1, (PrimitiveCircleObject) P2,
true);
o[1]=new LineCircleIntersectionObject(c,
(PrimitiveLineObject) P1, (PrimitiveCircleObject) P2,
false);
} else if (P2 instanceof QuadricObject) {
o=new IntersectionObject[2];
o[0]=new LineQuadricIntersectionObject(c,
(PrimitiveLineObject) P1, (QuadricObject) P2, true);
o[1]=new LineQuadricIntersectionObject(c,
(PrimitiveLineObject) P1, (QuadricObject) P2, false);
} else {
return construct(P2, P1, c);
}
} else if (P1 instanceof QuadricObject) {
if (P2 instanceof PrimitiveLineObject) {
o=new IntersectionObject[2];
o[0]=new LineQuadricIntersectionObject(c,
(PrimitiveLineObject) P2, (QuadricObject) P1, true);
o[1]=new LineQuadricIntersectionObject(c,
(PrimitiveLineObject) P2, (QuadricObject) P1, false);
} else if (P2 instanceof QuadricObject) {
if (((QuadricObject) P1).getP()[0].is3D()||((QuadricObject) P1).getP()[1].is3D()||((QuadricObject) P1).getP()[2].is3D()||((QuadricObject) P1).getP()[3].is3D()||((QuadricObject) P1).getP()[4].is3D()||
((QuadricObject) P2).getP()[0].is3D()||((QuadricObject) P2).getP()[1].is3D()||((QuadricObject) P2).getP()[2].is3D()||((QuadricObject) P2).getP()[3].is3D()||((QuadricObject) P2).getP()[4].is3D()) {// Dibs : truc de givré pour régler un bug avec l'intersection de cercles 3D
final PointObject p1=((QuadricObject) P1).getP()[1];
p1.setEX3D(p1.getEX3D().toString()+"+0.00001");
p1.setFixed("x(O)+("+p1.getEX3D()+")*(x(X)-x(O))+("+p1.getEY3D()+")*(x(Y)-x(O))+("+p1.getEZ3D()+")*(x(Z)-x(O))", "y(O)+("+p1.getEX3D()+")*(y(X)-y(O))+("+p1.getEY3D()+")*(y(Y)-y(O))+("+p1.getEZ3D()+")*(y(Z)-y(O))");
}
o=new IntersectionObject[4];
o[0]=new QuadricQuadricIntersectionObject(c,
(QuadricObject) P2, (QuadricObject) P1, 0);
o[1]=new QuadricQuadricIntersectionObject(c,
(QuadricObject) P2, (QuadricObject) P1, 1);
o[2]=new QuadricQuadricIntersectionObject(c,
(QuadricObject) P2, (QuadricObject) P1, 2);
o[3]=new QuadricQuadricIntersectionObject(c,
(QuadricObject) P2, (QuadricObject) P1, 3);
} else {
o=new PointonObjectIntersectionObject[1];
o[0]=new PointonObjectIntersectionObject(c, P1, P2);
}
} else if (P1 instanceof PrimitiveCircleObject) {
if (P2 instanceof PrimitiveCircleObject) {
if ((P1.isDPLineOrSegmentObject())&&(P2.isDPLineOrSegmentObject())) {
o=new IntersectionObject[1];
o[0]=new CircleIntersectionObject(c,
(PrimitiveCircleObject) P1, (PrimitiveCircleObject) P2,
true);
} else {
o=new IntersectionObject[2];
o[0]=new CircleIntersectionObject(c,
(PrimitiveCircleObject) P1, (PrimitiveCircleObject) P2,
true);
o[1]=new CircleIntersectionObject(c,
(PrimitiveCircleObject) P1, (PrimitiveCircleObject) P2,
false);
}
} else if (P2 instanceof PrimitiveLineObject) {
o=new IntersectionObject[2];
o[0]=new LineCircleIntersectionObject(c,
(PrimitiveLineObject) P2, (PrimitiveCircleObject) P1,
true);
o[1]=new LineCircleIntersectionObject(c,
(PrimitiveLineObject) P2, (PrimitiveCircleObject) P1,
false);
} else {
return construct(P2, P1, c);
}
} else {
o=new PointonObjectIntersectionObject[1];
o[0]=new PointonObjectIntersectionObject(c, P1, P2);
}
return o;
}
public ConstructionObject select(final int x, final int y, final ZirkelCanvas zc) // select a line or circle at x,y
{
return zc.selectPointonObject(x, y, false);
}
@Override
public void reset(final ZirkelCanvas zc) { // reset the tool
super.reset(zc);
if (zc.Visual) {
P1=P2=null;
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.intersection"));
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1==null) {
zc.showStatus(Global.name("message.intersection.first",
"Intersection: Select first object!"));
} else {
zc.showStatus(Global.name("message.intersection.second",
"Intersection: Select second object!"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Intersection")) {
return constructOther(tree, c);
}
final XmlTag tag=tree.getTag();
if (!tag.hasParam("first")||!tag.hasParam("second")) {
throw new ConstructionException("Intersection parameters missing!");
}
try {
final ConstructionObject o1=c.find(tag.getValue("first"));
final ConstructionObject o2=c.find(tag.getValue("second"));
final IntersectionObject o[]=construct(o1, o2, c);
if (o==null) {
throw new Exception("");
}
String name="", nameOther="";
if (tag.hasParam("name")) {
name=tag.getValue("name");
}
if (tag.hasParam("other")) {
nameOther=tag.getValue("other");
}
if (o.length>1) {
IntersectionObject oo=o[0];
if (tag.hasParam("which")) {
if (tag.getValue("which").equals("first")) {
oo=o[0];
} else if (tag.getValue("which").equals("second")) {
oo=o[1];
} else if (tag.getValue("which").equals("0")) {
oo=o[0];
} else if (tag.getValue("which").equals("1")) {
oo=o[1];
} else if (tag.getValue("which").equals("2")) {
oo=o[2];
} else if (tag.getValue("which").equals("3")) {
oo=o[3];
}
if (!name.equals("")) {
oo.setName(name);
}
PointConstructor.setType(tag, oo);
setName(tag, oo);
set(tree, oo);
c.add(oo);
setConditionals(tree, c, oo);
if (tag.hasParam("awayfrom")) {
oo.setAway(tag.getValue("awayfrom"), true);
} else if (tag.hasParam("closeto")) {
oo.setAway(tag.getValue("closeto"), false);
}
if (tag.hasParam("valid")) {
oo.setRestricted(false);
}
if (tag.hasParam("alternate")) {
oo.setAlternate(true);
}
} else if (tag.hasParam("other")) {
if (!name.equals("")) {
o[0].setName(name);
}
if (!nameOther.equals("")) {
o[1].setName(nameOther);
}
if (tag.hasParam("awayfrom")) {
o[0].setAway(tag.getValue("awayfrom"), true);
o[1].setAway(tag.getValue("awayfrom"), false);
} else if (tag.hasParam("closeto")) {
o[1].setAway(tag.getValue("awayfrom"), true);
o[0].setAway(tag.getValue("awayfrom"), false);
}
for (final IntersectionObject element : o) {
if (element==null) {
continue;
}
PointConstructor.setType(tag, element);
set(tree, element);
c.add(element);
setConditionals(tree, c, element);
}
}
} else {
if (!name.equals("")) {
o[0].setName(name);
}
PointConstructor.setType(tag, o[0]);
setName(tag, o[0]);
set(tree, o[0]);
c.add(o[0]);
setConditionals(tree, c, o[0]);
if (tag.hasParam("valid")) {
o[0].setRestricted(false);
}
try {
final double x=new Double(tag.getValue("x")).doubleValue();
final double y=new Double(tag.getValue("y")).doubleValue();
o[0].setXY(x, y);
} catch (final Exception e) {
}
}
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
//e.printStackTrace();
throw new ConstructionException("Intersection parameters illegal!");
}
return true;
}
public boolean constructOther(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "OtherIntersection")) {
return false;
}
final XmlTag tag=tree.getTag();
if (tag.hasParam("name")) {
final ConstructionObject o=c.find(tag.getValue("name"));
if (o==null||!(o instanceof IntersectionObject)) {
throw new ConstructionException("OtherIntersection not found!");
}
final IntersectionObject oo=(IntersectionObject) o;
PointConstructor.setType(tag, oo);
o.setDefaults();
set(tree, o);
final ConstructionObject ol=c.lastButN(1);
if (tag.hasParam("awayfrom")) {
oo.setAway(tag.getValue("awayfrom"), true);
if (ol!=null&&(ol instanceof IntersectionObject)) {
((IntersectionObject) ol).setAway(tag.getValue("awayfrom"),
false);
}
} else if (tag.hasParam("closeto")) {
oo.setAway(tag.getValue("closeto"), false);
if (ol!=null&&(ol instanceof IntersectionObject)) {
((IntersectionObject) ol).setAway(tag.getValue("awayfrom"),
true);
}
}
if (tag.hasParam("valid")) {
oo.setRestricted(false);
}
} else {
throw new ConstructionException(
"OtherIntersection must have a name!");
}
return true;
}
@Override
public String getTag() {
return "Intersection";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams!=2&&nparams!=3) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject p1=c.find(params[0]);
if (p1==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[0]);
}
final ConstructionObject p2=c.find(params[1]);
if (p2==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[0]);
}
final IntersectionObject o[]=construct(p1, p2, c);
if (o==null) {
throw new ConstructionException(Global.name("exception.type"));
}
if (o.length==1) {
c.add(o[0]);
o[0].setDefaults();
if (!name.equals("")) {
o[0].setName(name);
}
} else {
if (name.equals("")) {
for (final IntersectionObject element : o) {
c.add(element);
element.setDefaults();
}
} else {
final String names[]=new String[2];
int n;
if ((n=name.indexOf(','))>=0) {
names[0]=name.substring(n+1).trim();
names[1]=name.substring(0, n).trim();
} else {
names[0]=name;
names[1]="";
}
for (int i=0; i<o.length; i++) {
if (names[i].equals("")) {
continue;
}
c.add(o[i]);
o[i].setDefaults();
o[i].setName(names[i]);
}
}
}
}
}

View file

@ -0,0 +1,319 @@
/*
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.constructors;
// file: LineConstructor.java
import eric.JSelectPopup;
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.macro.Macro;
import rene.zirkel.objects.AxisObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.LineObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
import rene.zirkel.objects.PrimitiveLineObject;
public class LineConstructor extends ObjectConstructor {
PointObject P1=null, P2=null;
ConstructionObject O;
boolean Fix=false;
boolean ShowsValue, ShowsName, Moved;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
Fix=e.isShiftDown()||isFixed();
ConstructionObject obj;
if (Fix&&P1!=null&&!Dragging) { //Dibs, modif pour le segment de longueur fixe
obj= new PointObject(zc.getConstruction(),zc.x(e.getX()), zc.y(e.getY()));
((PointObject) obj).setUseAlpha(true);
zc.addObject(obj);
zc.validate();
obj.setDefaults();
zc.repaint();
obj.edit(zc, false, false);
zc.setNewPoint(true);
}
else {
obj=select(e.getX(), e.getY(), zc, e.isAltDown());
}
if (obj!=null) {
setConstructionObject(obj, zc);
} else {
Dragging=false;
}
}
@Override
public boolean waitForLastPoint() {
return P1!=null&&P2==null;
}
@Override
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc) {
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(obj instanceof PointonObject)) {
int x=JSelectPopup.getMouseX();
int y=JSelectPopup.getMouseY();
PointObject o=new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), obj);
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
obj=o;
}
if (P1==null) {
if (obj instanceof PointObject) {
// System.out.println("premier point="+obj.getName());
P1=(PointObject) obj;
P1.setSelected(true);
zc.repaint();
}
} else if (P2==null) {
if (obj instanceof PointObject) {
// System.out.println("deuxième point="+obj.getName());
P2=(PointObject) obj;
if (P2==P1) {
P2=null;
return;
}
final ConstructionObject o=create(zc.getConstruction(), P1,P2);
zc.addObject(o);
o.setDefaults();
if (P2.moveable()&&!P2.isPointOn()&&zc.isNewPoint()) {
Dragging=true;
Moved=false;
O=o;
ShowsValue=o.showValue();
ShowsName=o.showName();
if ((Fix&&Global.getParameter("options.movefixname", true))||(!Fix&&Global.getParameter("options.movename",
false))) {
o.setShowValue(true);
o.setShowName(true);
}
} else {
Dragging=false;
if (Fix) {
setFixed(zc, o);
}
P1=P2=null;
}
zc.clearSelected();
}
}
showStatus(zc);
}
@Override
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
P2=select(e.getX(), e.getY(), zc, e.isAltDown());
if (P2!=null) {
final ConstructionObject o=create(zc.getConstruction(), P1, P2);
zc.addObject(o);
o.setDefaults();
zc.validate();
zc.repaint();
P2=null;
}
}
@Override
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
};
Moved=true;
if (P2!=null) {
P2.move(zc.x(e.getX()), zc.y(e.getY()));
zc.validate();
zc.repaint();
}
}
@Override
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
}
Dragging=false;
O.setShowValue(ShowsValue);
O.setShowName(ShowsName);
if (Fix) {
O.round();
}
zc.repaint();
if (Fix&&!Moved) {
setFixed(zc, O);
} else {
try {
O.setFixed(false, O.getStringLength());
} catch (Exception ex) {}
}
reset(zc);
}
public boolean isFixed() {
return false;
}
public void setFixed(final ZirkelCanvas zc, final ConstructionObject o) {
}
public PointObject select(final int x, final int y, final ZirkelCanvas zc, boolean altdown) {
return zc.selectCreatePoint(x, y, altdown);
}
public ConstructionObject create(Construction c,PointObject p1, PointObject p2) {
return new LineObject(c, p1, p2);
}
@Override
public void reset(final ZirkelCanvas zc) {
if (!zc.Visual) {
zc.setPrompt(getPrompt());
} else {
zc.clearSelected();
P1=P2=null;
showStatus(zc);
}
}
public String getPrompt() {
return Global.name("prompt.line");
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1==null) {
zc.showStatus(Global.name("message.line.first",
"Line: Set the first point!"));
} else {
zc.showStatus(Global.name("message.line.second",
"Line: Set the second point!"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Line")) {
return false;
}
final XmlTag tag=tree.getTag();
if (tag.hasParam("xaxis")) {
final AxisObject o=new AxisObject(c, true);
setName(tag, o);
set(tree, o);
c.add(o);
c.xAxis=o;
return true;
}
if (tag.hasParam("yaxis")) {
final AxisObject o=new AxisObject(c, false);
setName(tag, o);
set(tree, o);
c.add(o);
c.yAxis=o;
return true;
}
if (!tag.hasParam("from")||!tag.hasParam("to")) {
if (!(c instanceof Macro)) {
throw new ConstructionException("Line points missing!");
}
final PrimitiveLineObject o=new PrimitiveLineObject(c);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
} else {
try {
final PointObject p1=(PointObject) c.find(tag.getValue("from"));
final PointObject p2=(PointObject) c.find(tag.getValue("to"));
final LineObject o=new LineObject(c, p1, p2);
if (tag.hasParam("partial")) {
o.setPartial(true);
}
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Line points illegal!");
}
}
return true;
}
@Override
public String getTag() {
return "Line";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams!=2) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject P1=c.find(params[0]);
if (P1==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[0]);
}
final ConstructionObject P2=c.find(params[1]);
if (P2==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[1]);
}
if (!(P1 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "+params[0]);
}
if (!(P2 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "+params[1]);
}
final LineObject s=new LineObject(c, (PointObject) P1,
(PointObject) P2);
c.add(s);
s.setDefaults();
if (!name.equals("")) {
s.setNameCheck(name);
}
}
}

View file

@ -0,0 +1,117 @@
/*
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.constructors;
// file: MidpointConstructor.java
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.MidpointObject;
import rene.zirkel.objects.PointObject;
public class MidpointConstructor extends LineConstructor {
@Override
public ConstructionObject create(final Construction c,
final PointObject p1, final PointObject p2) {
return new MidpointObject(c, p1, p2);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1 == null)
zc.showStatus(Global.name("message.midpoint.first",
"Midpoint: Set the first point!"));
else
zc.showStatus(Global.name("message.midpoint.second",
"Midpoint: Set the second point!"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Midpoint"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("first") || !tag.hasParam("second"))
throw new ConstructionException("Line points missing!");
try {
final PointObject p1 = (PointObject) c.find(tag.getValue("first"));
final PointObject p2 = (PointObject) c.find(tag.getValue("second"));
final MidpointObject p = new MidpointObject(c, p1, p2);
PointConstructor.setType(tag, p);
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Midpoint points illegal!");
}
return true;
}
@Override
public String getPrompt() {
return Global.name("prompt.midpoint");
}
@Override
public String getTag() {
return "Midpoint";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 2)
throw new ConstructionException(Global.name("exception.nparams"));
final ConstructionObject P1 = c.find(params[0]);
if (P1 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[0]);
if (!(P1 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[0]);
final ConstructionObject P2 = c.find(params[1]);
if (P2 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[1]);
if (!(P2 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[1]);
final MidpointObject s = new MidpointObject(c, (PointObject) P1,
(PointObject) P2);
if (!name.equals(""))
s.setNameCheck(name);
c.add(s);
s.setDefaults();
}
}

View file

@ -0,0 +1,328 @@
/*
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.constructors;
// file: ObjectConstructor.java
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTagText;
import rene.util.xml.XmlTree;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.ZirkelFrame;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
public class ObjectConstructor {
protected boolean Dragging=false;
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
}
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
}
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
}
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
// System.out.println("moved : "+e.getX()+" "+e.getY());
PointObject p=null;
if (simple&&(waitForPoint()||waitForLastPoint())) {
zc.indicateCreatePoint(e.getX(), e.getY(), false);
return;
}
if (waitForPoint()) {
p=zc.indicateCreatePoint(e.getX(), e.getY(), false);
}
if (waitForLastPoint()) {
if (zc.isPreview()) {
if (p==null) {
zc.movePreview(e);
} else {
zc.movePreview(p.getX(), p.getY());
}
} else {
zc.prepareForPreview(e);
finishConstruction(e, zc);
return;
}
}
}
public void setConstructionObject(ConstructionObject obj,ZirkelCanvas zc){
}
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
}
public boolean waitForLastPoint() {
return false;
}
public boolean waitForPoint() {
return true;
}
public void reset(final ZirkelCanvas zc) {
zc.validate();
zc.clearSelected();
}
public void resetFirstTime(final ZirkelCanvas zc) {
reset(zc);
}
public void invalidate(final ZirkelCanvas zc) {
zc.clearSelectionRectangle();
zc.clearMultipleSelection();
}
public void showStatus(final ZirkelCanvas zc) {
}
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
return false;
}
public boolean testTree(final XmlTree t, final String tag) {
return t.getTag().name().equals(tag);
}
public void setName(final XmlTag tag, final ConstructionObject o) {
if (tag.hasParam("name")) {
o.setName(tag.getValue("name"));
}
if (tag.hasParam("alias")) {
o.setAlias(tag.getValue("alias"));
}
}
public void set(XmlTree tree, final ConstructionObject o)
throws ConstructionException {
final XmlTag tag=tree.getTag();
if (tag.hasParam("n")) {
try {
o.setNCount(new Integer(tag.getValue("n")).intValue());
o.setGotNCount(true);
} catch (final Exception ex) {
throw new ConstructionException("Illegal count!");
}
}
if (tag.hasParam("hidden")) {
if (tag.getValue("hidden").equals("super")) {
o.setSuperHidden(true);
} else {
o.setHidden(true);
}
}
if (tag.hasTrueParam("tracked")) {
o.setTracked(true);
}
if (tag.hasTrueParam("showvalue")) {
o.setShowValue(true);
}
if (tag.hasTrueParam("showname")) {
o.setShowName(true);
}
if (tag.hasTrueParam("background")) {
o.setBack(true);
} else {
o.setBack(false);
}
if (tag.hasTrueParam("parameter")) {
o.setParameter(true);
}
if (tag.hasTrueParam("mainparameter")) {
o.setMainParameter(true);
}
if (tag.hasTrueParam("target")) {
o.setTarget(true);
}
if (tag.hasParam("macroFinalIndex")) {
int x=Integer.parseInt(tag.getValue("macroFinalIndex"));
o.setMacroFinalIndex(x);
}
if (tag.hasTrueParam("break")) {
o.setBreak(true);
}
if (tag.hasTrueParam("hidebreak")) {
o.setHideBreak(true);
}
if (tag.hasTrueParam("solid")) {
o.setSolid(true);
}
if (tag.hasTrueParam("bold")) {
o.setBold(true);
}
if (tag.hasTrueParam("large")) {
o.setLarge(true);
}
if (tag.hasParam("dp_mode")) {
int x=Integer.parseInt(tag.getValue("dp_mode"));
o.setDPMode(x);
}
if (tag.hasParam("xoffset")||tag.hasParam("yoffset")) {
int x=0, y=0;
try {
if (tag.hasParam("xoffset")) {
x=Integer.parseInt(tag.getValue("xoffset"));
}
if (tag.hasParam("yoffset")) {
y=Integer.parseInt(tag.getValue("yoffset"));
}
o.setOffset(x, y);
} catch (final Exception e) {
throw new ConstructionException("Illegal offset value");
}
}
if (tag.hasTrueParam("keepclose")) {
o.setKeepClose(true);
}
if (tag.hasParam("xcoffset")||tag.hasParam("ycoffset")) {
double x=0, y=0;
try {
if (tag.hasParam("xcoffset")) {
x=new Double(tag.getValue("xcoffset")).doubleValue();
}
if (tag.hasParam("ycoffset")) {
y=new Double(tag.getValue("ycoffset")).doubleValue();
}
o.setcOffset(x, y);
} catch (final Exception e) {
throw new ConstructionException("Illegal offset value");
}
}
if (tag.hasParam("color")) {
try {
final String s=tag.getValue("color");
int n=-1;
for (int i=0; i<ZirkelFrame.ColorStrings.length; i++) {
if (s.equals(ZirkelFrame.ColorStrings[i])) {
o.setColor(i);
n=i;
break;
}
}
if (n<0) {
n=Integer.parseInt(s);
if (n<0||n>=ZirkelFrame.Colors.length) {
throw new Exception("");
}
o.setColor(n);
}
} catch (final Exception ex) {
throw new ConstructionException("Illegal color index (1-"
+(ZirkelFrame.Colors.length-1)+")");
}
}
if (tag.hasParam("scolor")) {
String reg="([0-9]+),([0-9]+),([0-9]+)";
Matcher m=Pattern.compile(reg).matcher(tag.getValue("scolor"));
// Si une couleur RGB est trouvée, dans un format antérieur à la 3.5.5,
// soit par exemple "175,250,99" :
if (m.find()) {
int red=Integer.parseInt(m.group(1));
int green=Integer.parseInt(m.group(2));
int blue=Integer.parseInt(m.group(3));
o.setSpecialColor(new Color(red, green, blue));
} else {
reg="(.+),,(.+),,(.+)";
m=Pattern.compile(reg).matcher(tag.getValue("scolor"));
// Si une couleur RGB est trouvée, dans un format à partir de la 3.5.5,
// soit par exemple "x(A)*255,,y(A)*255,,99" :
if (m.find()) {
o.setSpecialColor(m.group(1), m.group(2), m.group(3));
}
}
}
if (tag.hasParam("type")) {
final String type=tag.getValue("type");
if (type.equals("thick")) {
o.setColorType(ConstructionObject.THICK);
}
if (type.equals("thin")) {
o.setColorType(ConstructionObject.THIN);
}
if (type.equals("invisible")) {
o.setColorType(ConstructionObject.INVISIBLE);
}
}
if (tag.hasParam("unit")) {
o.setUnit(tag.getValue("unit"));
} else {
o.setUnit("");
}
final Enumeration e=tree.getContent();
while (e.hasMoreElements()) {
tree=(XmlTree) e.nextElement();
if (tree.getTag() instanceof XmlTagText) {
o.setText(((XmlTagText) tree.getTag()).getContent(), true);
}
}
}
public void setConditionals(final XmlTree tree, final Construction c,
final ConstructionObject o) {
o.clearConditionals();
int i=0;
final XmlTag tag=tree.getTag();
while (tag.hasParam("ctag"+i)&&tag.hasParam("cexpr"+i)) {
final String t=tag.getValue("ctag"+i);
final String e=tag.getValue("cexpr"+i);
final Expression ex=new Expression(e, c, o);
o.addConditional(t, ex);
i++;
}
}
public String getTag() {
return "???";
}
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
throw new ConstructionException("");
}
// for MetaMover :
public void pause(final boolean flag) {
}
public boolean useSmartBoard() {
return true;
}
}

View file

@ -0,0 +1,243 @@
/*
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.constructors;
// file: ParallelConstructor.java
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.ParallelObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PrimitiveLineObject;
public class ParallelConstructor extends ObjectConstructor {
PointObject P=null;
PrimitiveLineObject L=null;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
if (!zc.Visual) {
return;
}
ConstructionObject obj=null;
if (L==null) {
obj=selectline(e.getX(), e.getY(), zc);
} else {
obj=select(e.getX(), e.getY(), zc, e.isAltDown());
}
setConstructionObject(obj, zc);
}
@Override
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc) {
if (L==null) {
if (obj instanceof PrimitiveLineObject) {
L=(PrimitiveLineObject) obj;
L.setSelected(true);
zc.repaint();
}
} else if (P==null) {
if (obj instanceof PointObject) {
P=(PointObject) obj;
final ConstructionObject o=create(zc.getConstruction(), L, P);
zc.addObject(o);
o.setDefaults();
P=null;
L=null;
zc.clearSelected();
}
}
showStatus(zc);
}
@Override
public boolean waitForLastPoint() {
return L!=null;
}
@Override
public void finishConstruction(final MouseEvent e, final ZirkelCanvas zc) {
P=select(e.getX(), e.getY(), zc, e.isAltDown());
if (P!=null) {
final ConstructionObject o=create(zc.getConstruction(), L, P);
zc.addObject(o);
o.setDefaults();
zc.validate();
zc.repaint();
P=null;
}
}
// @Override
// public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
// final boolean simple) {
// if (!simple && waitForLastPoint()) {
// if (zc.isPreview()) {
// zc.movePreview(e);
// } else {
// zc.prepareForPreview(e);
// finishConstruction(e, zc);
// }
// }
// if (L == null)
// zc.indicateLineObjects(e.getX(), e.getY());
// else if (P == null)
// zc.indicateCreatePoint(e.getX(), e.getY(), false);
// }
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc,
final boolean simple) {
if (L==null) {
zc.indicateLineObjects(e.getX(), e.getY());
} else if (P==null) {
PointObject p=zc.indicateCreatePoint(e.getX(), e.getY(), false);
if (!simple&&waitForLastPoint()) {
if (zc.isPreview()) {
if (p==null) {
zc.movePreview(e);
} else {
zc.movePreview(p.getX(), p.getY());
}
} else {
zc.prepareForPreview(e);
finishConstruction(e, zc);
}
}
}
}
public PointObject select(final int x, final int y, final ZirkelCanvas zc, boolean altdown) {
return zc.selectCreatePoint(x, y, altdown);
}
public PrimitiveLineObject selectline(final int x, final int y,
final ZirkelCanvas zc) {
return zc.selectLine(x, y);
}
public PrimitiveLineObject create(final Construction c,
final PrimitiveLineObject l, final PointObject p) {
return new ParallelObject(c, l, p);
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
P=null;
L=null;
showStatus(zc);
} else {
zc.setPrompt(getPrompt());
}
}
public String getPrompt() {
return Global.name("prompt.parallel");
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (L==null) {
zc.showStatus(Global.name("message.parallel.first",
"Parallel: Choose a line!"));
} else {
zc.showStatus(Global.name("message.parallel.second",
"Parallel: Choose a Point!"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Parallel")) {
return false;
}
final XmlTag tag=tree.getTag();
if (!tag.hasParam("point")||!tag.hasParam("line")) {
throw new ConstructionException("Parallel parameters missing!");
}
try {
final PointObject p1=(PointObject) c.find(tag.getValue("point"));
final PrimitiveLineObject p2=(PrimitiveLineObject) c.find(tag.getValue("line"));
final ParallelObject o=new ParallelObject(c, p2, p1);
setName(tag, o);
set(tree, o);
if (tag.hasParam("partial")) {
o.setPartial(true);
}
c.add(o);
setConditionals(tree, c, o);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Parallel parameters illegal!");
}
return true;
}
@Override
public String getTag() {
return "Parallel";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams!=2) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject P1=c.find(params[0]);
if (P1==null) {
throw new ConstructionException(Global.name("exception.notfound")
+" "+params[0]);
}
final ConstructionObject P2=c.find(params[1]);
if (P2==null) {
throw new ConstructionException(Global.name("exception.notfound")
+" "+params[1]);
}
if (!(P1 instanceof PrimitiveLineObject)) {
throw new ConstructionException(Global.name("exception.type")+" "
+params[0]);
}
if (!(P2 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "
+params[1]);
}
final ParallelObject s=new ParallelObject(c,
(PrimitiveLineObject) P1, (PointObject) P2);
if (!name.equals("")) {
s.setNameCheck(name);
}
c.add(s);
s.setDefaults();
}
}

View file

@ -0,0 +1,121 @@
/*
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.constructors;
// file: PlumbConstructor.java
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PlumbObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PrimitiveLineObject;
public class PlumbConstructor extends ParallelConstructor {
@Override
public PrimitiveLineObject create(final Construction c,
final PrimitiveLineObject l, final PointObject p) {
return new PlumbObject(c, l, p);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (L == null)
zc.showStatus(Global.name("message.plumb.first",
"Plumb Line: Choose a line!"));
else
zc.showStatus(Global.name("message.plumb.second",
"Plumb Line: Choose a Point!"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Plumb"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("point") || !tag.hasParam("line"))
throw new ConstructionException("Plumb parameters missing!");
try {
final PointObject p1 = (PointObject) c.find(tag.getValue("point"));
final PrimitiveLineObject p2 = (PrimitiveLineObject) c.find(tag
.getValue("line"));
final PlumbObject o = new PlumbObject(c, p2, p1);
if (tag.hasParam("valid"))
o.setRestricted(false);
setName(tag, o);
set(tree, o);
if (tag.hasParam("partial"))
o.setPartial(true);
c.add(o);
setConditionals(tree, c, o);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Plumb parameters illegal!");
}
return true;
}
@Override
public String getPrompt() {
return Global.name("prompt.plumb");
}
@Override
public String getTag() {
return "Plumb";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 2)
throw new ConstructionException(Global.name("exception.nparams"));
final ConstructionObject P1 = c.find(params[0]);
if (P1 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[0]);
final ConstructionObject P2 = c.find(params[1]);
if (P2 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[1]);
if (!(P1 instanceof PrimitiveLineObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[0]);
if (!(P2 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[1]);
final PlumbObject s = new PlumbObject(c, (PrimitiveLineObject) P1,
(PointObject) P2);
if (!name.equals(""))
s.setNameCheck(name);
c.add(s);
s.setDefaults();
}
}

View file

@ -0,0 +1,308 @@
/*
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.constructors;
// file: PointConstructor.java
import java.util.ArrayList;
import java.util.Enumeration;
import eric.JSelectPopup;
import eric.GUI.palette.PaletteManager;
import eric.bar.JPropertiesBar;
import java.awt.event.MouseEvent;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.AreaObject;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
import rene.zirkel.objects.PrimitiveCircleObject;
import rene.zirkel.objects.PrimitiveLineObject;
public class PointConstructor extends ObjectConstructor {
// boolean Fix;
PointObject P;
boolean ShowsValue, ShowsName;
boolean ShiftDown=false;
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
ShiftDown=e.isShiftDown();
final PointObject o=zc.selectCreatePoint(e.getX(), e.getY(), false,
true, e.isAltDown());
setConstructionObject(o, zc);
}
@Override
public void setConstructionObject(ConstructionObject obj, ZirkelCanvas zc) {
Dragging=false;
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(obj instanceof PointonObject)) {
int x=JSelectPopup.getMouseX();
int y=JSelectPopup.getMouseY();
PointObject o=new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), obj);
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
} else if (obj instanceof PointObject) {
PointObject o=(PointObject) obj;
if (o.isPointOn()) // create a point on an object
{
if (ShiftDown&&zc.isNewPoint()) {
o.setUseAlpha(true);
}
} else if (o.moveable()&&zc.isNewPoint()&&!zc.getAxis_show()) {
P=o;
ShowsValue=P.showValue();
ShowsName=P.showName();
Dragging=true;
zc.repaint();
} else if (o.moveable()&&zc.isNewPoint()&&zc.getAxis_show()&&ShiftDown) {
P=o;
try {
P.setFixed(""+P.round(P.getX(), ZirkelCanvas.LengthsFactor),
""+P.round(P.getY(), ZirkelCanvas.LengthsFactor));
P.edit(zc, true, true);
P.validate();
} catch (final Exception ex) {
}
} else if (ShiftDown&&!zc.isNewPoint()) {
final PointObject p=new PointObject(zc.getConstruction(), o.getX(), o.getY());
zc.addObject(p);
p.setFixed(true);
}
}
}
@Override
public void mouseDragged(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
}
if (Global.getParameter("options.movename", false)) {
P.setShowValue(true);
P.setShowName(true);
}
P.move(zc.x(e.getX()), zc.y(e.getY()));
zc.repaint();
}
@Override
public void mouseReleased(final MouseEvent e, final ZirkelCanvas zc) {
if (!Dragging) {
return;
}
Dragging=false;
P.setShowValue(ShowsValue);
P.setShowName(ShowsName);
P.updateText();
zc.repaint();
if (ShiftDown) {
try {
P.setFixed(""+P.round(P.getX(), ZirkelCanvas.LengthsFactor),
""+P.round(P.getY(), ZirkelCanvas.LengthsFactor));
JPropertiesBar.EditObject(P);
P.validate();
} catch (final Exception ex) {
}
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.point", "Point: Set a point!"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Point")) {
return false;
}
final XmlTag tag=tree.getTag();
if (!tag.hasParam("x")||!tag.hasParam("y")) {
throw new ConstructionException("Point coordinates missing!");
}
double x=0, y=0;
double x3D=0, y3D=0, z3D=0;
try {
if (tag.hasParam("actx")) {
x=new Double(tag.getValue("actx")).doubleValue();
// System.out.println(x);
}
if (tag.hasParam("acty")) {
y=new Double(tag.getValue("acty")).doubleValue();
}
} catch (final Exception e) {
}
final PointObject p=new PointObject(c, x, y);
try {
x=new Expression(tag.getValue("x"), c, p).getValue();
y=new Expression(tag.getValue("y"), c, p).getValue();
p.move(x, y);
} catch (final Exception e) {
}
if (tag.hasParam("is3D")) {
p.setIs3D(true);
try {
x3D=new Expression(tag.getValue("x3D"), c, p).getValue();
y3D=new Expression(tag.getValue("y3D"), c, p).getValue();
z3D=new Expression(tag.getValue("z3D"), c, p).getValue();
p.move3D(x3D, y3D, z3D);
} catch (final Exception e) {
}
}
setType(tag, p);
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
if (tag.hasParam("fixed")) {
p.setFixed(tag.getValue("x"), tag.getValue("y"));
}
if (tag.hasParam("fixed3D")) {
p.setFixed(tag.getValue("x3D"), tag.getValue("y3D"), tag.getValue("z3D"));
}
if (tag.hasParam("increment")) {
try {
p.setIncrement(new Double(tag.getValue("increment")).doubleValue());
} catch (final Exception e) {
}
}
if (tag.hasParam("magnetobjs")) {
// must manage the magnet list after the whole construction is
// loaded (see zc.load)
c.magnet.add(p);
c.magnet.add(tag.getValue("magnetobjs"));
p.setMagnetRayExp(tag.getValue("magnetd"));
}
return true;
}
static public void setType(final XmlTag tag, final PointObject p) {
if (tag.hasParam("shape")) {
final String s=tag.getValue("shape");
if (s.equals("square")) {
p.setType(0);
}
if (s.equals("diamond")) {
p.setType(1);
}
if (s.equals("circle")) {
p.setType(2);
}
if (s.equals("dot")) {
p.setType(3);
}
if (s.equals("cross")) {
p.setType(4);
}
if (s.equals("dcross")) {
p.setType(5);
}
}
}
@Override
public String getTag() {
return "Point";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams==0) {
final PointObject p=new PointObject(c, c.getX()+(Math.random()-0.5)*c.getW(), c.getY()+(Math.random()-0.5)*c.getW());
if (!name.equals("")) {
p.setNameCheck(name);
}
c.add(p);
p.setDefaults();
return;
}
if (nparams==1) {
final ConstructionObject o=c.find(params[0]);
if (o==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[0]);
}
if (!(o instanceof PrimitiveLineObject)&&!(o instanceof PrimitiveCircleObject)) {
throw new ConstructionException(Global.name("exception.type")+" "+params[0]);
}
final PointObject p=new PointObject(c, c.getX()+(Math.random()-0.5)*c.getW(), c.getY()+(Math.random()-0.5)*c.getW(), o);
if (!name.equals("")) {
p.setNameCheck(name);
}
c.add(p);
p.setDefaults();
return;
}
if (nparams!=2) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final Expression e1=new Expression(params[0], c, null);
final Expression e2=new Expression(params[1], c, null);
if (!e1.isValid()||!e2.isValid()) {
throw new ConstructionException(Global.name("exception.expression"));
}
final PointObject p=new PointObject(c, 0, 0);
try {
final double x=new Double(params[0]).doubleValue();
final double y=new Double(params[1]).doubleValue();
p.move(x, y);
} catch (final Exception e) {
p.setFixed(params[0], params[1]);
}
c.add(p);
p.validate();
p.setDefaults();
if (!name.equals("")) {
p.setNameCheck(name);
}
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
zc.setPrompt(Global.name("prompt.point"));
}
}

View file

@ -0,0 +1,244 @@
/*
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.constructors;
// file: QuadricConstructor.java
import eric.JSelectPopup;
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.PointonObject;
import rene.zirkel.objects.QuadricObject;
public class QuadricConstructor extends ObjectConstructor {
private PointObject Points[];
private int NPoints;
private static PointObject previewPoint;
private QuadricObject Quadric;
private boolean newPoint = false;
public static void deletePreview(final ZirkelCanvas zc) {
zc.reset();
}
public void validQuadric(ZirkelCanvas zc){
if(Quadric!=null){
zc.clearSelected();
Quadric.updateText();
initialize();
}
}
public void initialize(){
previewPoint = null;
Quadric = null;
NPoints = 0;
Points = new PointObject[5];
}
private void arrangePoints() {
if (NPoints<5) {
Points[4]=previewPoint;
for (int i=3; i>=NPoints; i--) {
Points[i]=Points[0];
}
}
}
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc){
if (!zc.Visual) {
return;
}
if (previewPoint==null) {
previewPoint = new PointObject(zc.getConstruction(), "PrevPoint");
}
HideQuadric(true);
final PointObject P = zc.selectCreatePoint(e.getX(), e.getY(), e.isAltDown());
HideQuadric(false);
newPoint = newPoint || zc.isNewPoint();
setConstructionObject(P, zc);
}
@Override
public void setConstructionObject(ConstructionObject P, ZirkelCanvas zc){
// Il y a eu ambiguité et la méthode est forcément appelée par le
// popupmenu de sélection :
if ((JSelectPopup.isCallerObject())&&(P instanceof PointonObject)) {
int x = JSelectPopup.getMouseX();
int y = JSelectPopup.getMouseY();
PointObject o = new PointObject(zc.getConstruction(), zc.x(x), zc.y(y), P);
newPoint = true;
o.setUseAlpha(true);
zc.addObject(o);
zc.validate();
o.setDefaults();
zc.repaint();
o.edit(zc, false, false);
P=o;
}
if(P!=null){
Points[NPoints++] = (PointObject)P;
P.setSelected(true);
if(Quadric==null){
arrangePoints();
Quadric = new QuadricObject(zc.getConstruction(), Points);
zc.addObject(Quadric);
Quadric.setDefaults();
zc.repaint();
}
if (NPoints==5) {
validQuadric(zc);
// Si on a créé un sommet à la volée, il faut réorganiser la construction
// pour éviter un pb de dépendance
if(newPoint){
zc.getConstruction().reorderConstruction();
zc.reloadCD();
newPoint = false;
}
}
}
showStatus(zc);
}
public void HideQuadric(boolean b){
if(Quadric!=null)
Quadric.setHidden(b);
}
@Override
public void mouseMoved(final MouseEvent e, final ZirkelCanvas zc, final boolean simple) {
if (previewPoint!=null) {
previewPoint.move(zc.x(e.getX()), zc.y(e.getY()));
HideQuadric(true);
if (waitForPoint()) {
PointObject pt = zc.indicateCreatePoint(e.getX(), e.getY(), false);
if (zc.getConstruction().indexOf(pt)!=-1) {
previewPoint.move(pt.getX(), pt.getY());
}
}
HideQuadric(false);
Quadric.setDefaults();
Quadric.validate();
zc.repaint();
}
else super.mouseMoved(e, zc, simple);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.quadric")+" "+(NPoints+1));
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
if (zc.Visual) {
if(Quadric!=null){
zc.delete(Quadric);
}
initialize();
showStatus(zc);
} else {
zc.setPrompt(Global.name("prompt.quadric"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Quadric")) {
return false;
}
final XmlTag tag=tree.getTag();
for (int i=0; i<5; i++) {
if (!tag.hasParam("point"+(i+1))) {
throw new ConstructionException("Quadric points missing!");
}
}
try {
final PointObject P[]=new PointObject[5];
for (int i=0; i<5; i++) {
P[i]=(PointObject) c.find(tag.getValue("point"+(i+1)));
}
final QuadricObject p=new QuadricObject(c, P);
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Quadric points illegal!");
}
return true;
}
public String getPrompt() {
return Global.name("prompt.quadric");
}
@Override
public String getTag() {
return "Quadric";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams!=5) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject P[]=new PointObject[5];
for (int i=0; i<5; i++) {
P[i]=c.find(params[i]);
if (P[i]==null) {
throw new ConstructionException(Global.name("exception.notfound")
+" "+params[i]);
}
if (!(P[i] instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")
+" "+params[i]);
}
}
final QuadricObject s=new QuadricObject(c, (PointObject[]) P);
if (!name.equals("")) {
s.setNameCheck(name);
}
c.add(s);
s.setDefaults();
}
}

View file

@ -0,0 +1,121 @@
/*
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.constructors;
// file: RayConstructor.java
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.RayObject;
public class RayConstructor extends LineConstructor {
@Override
public ConstructionObject create(final Construction c,
final PointObject p1, final PointObject p2) {
return new RayObject(c, p1, p2);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1==null) {
zc.showStatus(Global.name("message.ray.first",
"Ray: Set the root point!"));
} else {
zc.showStatus(Global.name("message.ray.second",
"Ray: Set the second point!"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Ray")) {
return false;
}
final XmlTag tag=tree.getTag();
if (!tag.hasParam("from")||!tag.hasParam("to")) {
throw new ConstructionException("Ray points missing!");
}
try {
final PointObject p1=(PointObject) c.find(tag.getValue("from"));
final PointObject p2=(PointObject) c.find(tag.getValue("to"));
final RayObject o=new RayObject(c, p1, p2);
if (tag.hasParam("partial")) {
o.setPartial(true);
}
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
e.printStackTrace();
throw new ConstructionException("Ray points illegal!");
}
return true;
}
@Override
public String getPrompt() {
return Global.name("prompt.ray");
}
@Override
public String getTag() {
return "Ray";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams!=2) {
throw new ConstructionException(Global.name("exception.nparams"));
}
final ConstructionObject P1=c.find(params[0]);
if (P1==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[0]);
}
final ConstructionObject P2=c.find(params[1]);
if (P2==null) {
throw new ConstructionException(Global.name("exception.notfound")+" "+params[1]);
}
if (!(P1 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "+params[0]);
}
if (!(P2 instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type")+" "+params[1]);
}
final RayObject s=new RayObject(c, (PointObject) P1, (PointObject) P2);
c.add(s);
s.setDefaults();
if (!name.equals("")) {
s.setNameCheck(name);
}
}
}

View file

@ -0,0 +1,192 @@
/*
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.constructors;
// file: SegmentConstructor.java
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.SegmentObject;
public class SegmentConstructor extends LineConstructor {
boolean Fixed = false;
public SegmentConstructor() {
this(false);
}
public SegmentConstructor(final boolean fixed) {
Fixed = fixed;
}
@Override
public ConstructionObject create(final Construction c,
final PointObject p1, final PointObject p2) {
return new SegmentObject(c, p1, p2);
}
@Override
public boolean isFixed() {
return Fixed;
}
@Override
public void setFixed(final ZirkelCanvas zc, final ConstructionObject o) {
if (o instanceof SegmentObject) {
final SegmentObject s = (SegmentObject) o;
if (s.canFix())
try {
s.validate();
s.setFixed(true, "" + s.getLength());
s.edit(zc, true, true);
s.validate();
zc.repaint();
} catch (final Exception e) {
}
else {
zc.warning(Global.name("error.fixedsegment"));
}
}
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (!Fixed) {
if (P1 == null)
zc.showStatus(Global.name("message.segment.first"));
else
zc.showStatus(Global.name("message.segment.second"));
} else {
if (P1 == null)
zc.showStatus(Global.name("message.fixedsegment.first"));
else
zc.showStatus(Global.name("message.fixedsegment.second"));
}
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Segment"))
return false;
final XmlTag tag = tree.getTag();
if(tag.hasParam("arrow"))
return false; //parceque VectorConstructor est appelé après dans l'ordre chronologique
if (!tag.hasParam("from") || !tag.hasParam("to"))
throw new ConstructionException("Segment endpoints missing!");
try {
final PointObject p1 = (PointObject) c.find(tag.getValue("from"));
final PointObject p2 = (PointObject) c.find(tag.getValue("to"));
final SegmentObject o = new SegmentObject(c, p1, p2);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
//o.setArrow(tag.hasParam("arrow")); plus nécessaire
if (tag.hasParam("fixed")) {
try {
o.setFixed(true, tag.getValue("fixed"));
} catch (final Exception e) {
throw new ConstructionException("Fixed value illegal!");
}
}
if (tag.hasParam("code_symbol"))
o.setSegmentCode(Integer.parseInt(tag.getValue("code_symbol")));
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Segment endpoints illegal!");
}
return true;
}
@Override
public String getPrompt() {
return Global.name("prompt.segment");
}
@Override
public String getTag() {
return "Segment";
}
@Override
public void construct(final Construction c, final String name,
final String params[], final int nparams)
throws ConstructionException {
if (nparams != 2 && nparams != 3)
throw new ConstructionException(Global.name("exception.nparams"));
final ConstructionObject P1 = c.find(params[0]);
if (P1 == null)
throw new ConstructionException(Global.name("exception.notfound")
+ " " + params[0]);
if (!(P1 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[0]);
ConstructionObject P2 = c.find(params[1]);
if (P2 == null) {
final Expression ex = new Expression(params[1], c, null);
if (!ex.isValid())
throw new ConstructionException(Global.name("exception.expression"));
final double x = ex.getValue();
P2 = new PointObject(c, ((PointObject) P1).getX() + x,
((PointObject) P1).getY());
c.add(P2);
P2.setDefaults();
final SegmentObject s = new SegmentObject(c, (PointObject) P1,
(PointObject) P2);
s.setDefaults();
s.setFixed(true, params[1]);
c.add(s);
if (!name.equals(""))
s.setNameCheck(name);
return;
}
if (!(P2 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "
+ params[1]);
final SegmentObject s = new SegmentObject(c, (PointObject) P1,
(PointObject) P2);
if (nparams == 3) {
if (!s.canFix())
throw new ConstructionException(Global.name("exception.canfix"));
s.setFixed(true, params[2]);
if (!s.isValidFix())
throw new ConstructionException(Global.name("exception.fix")
+ " " + params[2]);
s.validate();
}
c.add(s);
s.setDefaults();
// s.setArrow(c.isVector());
if (!name.equals(""))
s.setNameCheck(name);
}
}

View file

@ -0,0 +1,90 @@
/*
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.constructors;
// file: PointConstructor.java
import java.awt.event.MouseEvent;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.gui.Global;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.TextObject;
public class TextConstructor extends ObjectConstructor {
@Override
public void mousePressed(final MouseEvent e, final ZirkelCanvas zc) {
final double x = zc.x(e.getX()), y = zc.y(e.getY());
final TextObject p = new TextObject(zc.getConstruction(), x, y);
zc.addObject(p);
p.edit(zc, true, true);
p.setDefaults();
zc.repaint();
}
@Override
public boolean waitForPoint() {
return false;
}
@Override
public void showStatus(final ZirkelCanvas zc) {
zc.showStatus(Global.name("message.text"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c)
throws ConstructionException {
if (!testTree(tree, "Text"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("x") || !tag.hasParam("y"))
throw new ConstructionException("Point coordinates missing!");
final TextObject p = new TextObject(c, 0, 0);
double x, y;
try {
x = new Expression(tag.getValue("x"), c, p).getValue();
y = new Expression(tag.getValue("y"), c, p).getValue();
p.move(x, y);
} catch (final Exception e) {
}
setName(tag, p);
set(tree, p);
c.add(p);
setConditionals(tree, c, p);
p.setLines(p.getText());
if (tag.hasParam("fixed")) {
p.setFixed(tag.getValue("x"), tag.getValue("y"));
}
return true;
}
@Override
public void reset(final ZirkelCanvas zc) {
super.reset(zc);
showStatus(zc);
}
}

View file

@ -0,0 +1,145 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package rene.zirkel.constructors;
import rene.gui.Global;
import rene.util.xml.XmlTag;
import rene.util.xml.XmlTree;
import rene.zirkel.ZirkelCanvas;
import rene.zirkel.construction.Construction;
import rene.zirkel.construction.ConstructionException;
import rene.zirkel.expression.Expression;
import rene.zirkel.objects.ConstructionObject;
import rene.zirkel.objects.PointObject;
import rene.zirkel.objects.VectorObject;
/**
*
* @author PM
*/
public class VectorConstructor extends SegmentConstructor{
public VectorConstructor(){
this(false);
}
public VectorConstructor(boolean fixed){
Fixed = fixed;
}
@Override
public ConstructionObject create(final Construction c, final PointObject p1, final PointObject p2) {
return new VectorObject(c, p1, p2);
}
@Override
public void showStatus(final ZirkelCanvas zc) {
if (P1 == null)
zc.showStatus(Global.name("message.vector.first"));
else
zc.showStatus(Global.name("message.vector.second"));
}
@Override
public boolean construct(final XmlTree tree, final Construction c) throws ConstructionException {
if (!testTree(tree, "Segment"))
return false;
final XmlTag tag = tree.getTag();
if (!tag.hasParam("from") || !tag.hasParam("to"))
throw new ConstructionException("Segment endpoints missing!");
try {
final PointObject p1 = (PointObject) c.find(tag.getValue("from"));
final PointObject p2 = (PointObject) c.find(tag.getValue("to"));
final VectorObject o = new VectorObject(c, p1, p2);
setName(tag, o);
set(tree, o);
c.add(o);
setConditionals(tree, c, o);
//o.setArrow(tag.hasParam("arrow"));
if(tag.hasParam("x") && tag.hasParam("y")){
o.setEXY(tag.getValue("x"), tag.getValue("y"));
}
if (tag.hasParam("is3D")) {
o.setIs3D(true);
}
if(tag.hasParam("x3D") && tag.hasParam("y3D")&& tag.hasParam("z3D")){
o.setEXYZ(tag.getValue("x3D"), tag.getValue("y3D"), tag.getValue("z3D"));
}
if (tag.hasParam("fixed")) {
try {
o.setFixed(true, tag.getValue("fixed"));
} catch (final Exception e) {
throw new ConstructionException("Fixed value illegal!");
}
}
if (tag.hasParam("fixed3D")) {
try {
o.setFixed(true, tag.getValue("fixed3D"));
} catch (final Exception e) {
throw new ConstructionException("Fixed 3D value illegal!");
}
}
if (tag.hasParam("code_symbol"))
o.setSegmentCode(Integer.parseInt(tag.getValue("code_symbol")));
} catch (final ConstructionException e) {
throw e;
} catch (final Exception e) {
throw new ConstructionException("Segment endpoints illegal!");
}
return true;
}
@Override
public void construct(final Construction c, final String name, final String params[], final int nparams)
throws ConstructionException {
if (nparams != 2 && nparams != 3)
throw new ConstructionException(Global.name("exception.nparams"));
final ConstructionObject P1 = c.find(params[0]);
if (P1 == null)
throw new ConstructionException(Global.name("exception.notfound")+ " " + params[0]);
if (!(P1 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "+ params[0]);
ConstructionObject P2 = c.find(params[1]);
if (P2 == null) {
final Expression ex = new Expression(params[1], c, null);
if (!ex.isValid())
throw new ConstructionException(Global.name("exception.expression"));
final double x = ex.getValue();
P2 = new PointObject(c, ((PointObject) P1).getX() + x, ((PointObject) P1).getY());
c.add(P2);
P2.setDefaults();
final VectorObject s = new VectorObject(c, (PointObject) P1, (PointObject) P2);
s.setDefaults();
s.setFixed(true, params[1]);
c.add(s);
if (!name.equals(""))
s.setNameCheck(name);
return;
}
if (!(P2 instanceof PointObject))
throw new ConstructionException(Global.name("exception.type") + " "+ params[1]);
final VectorObject s = new VectorObject(c, (PointObject) P1, (PointObject) P2);
if (nparams == 3) {
if (!s.canFix())
throw new ConstructionException(Global.name("exception.canfix"));
s.setFixed(true, params[2]);
if (!s.isValidFix())
throw new ConstructionException(Global.name("exception.fix")+ " " + params[2]);
s.validate();
}
c.add(s);
s.setDefaults();
// s.setArrow(c.isVector());
if (!name.equals(""))
s.setNameCheck(name);
}
}