/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package eric.JSprogram; import eric.*; import eric.GUI.palette.PaletteManager; import eric.GUI.pipe_tools; import java.awt.Color; import java.awt.FileDialog; import java.io.File; import java.util.Enumeration; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import rene.gui.Global; import rene.util.FileName; import rene.zirkel.ZirkelCanvas; import rene.zirkel.construction.Construction; import rene.zirkel.construction.ConstructionException; import rene.zirkel.constructors.ObjectConstructor; import rene.zirkel.expression.Expression; import rene.zirkel.macro.MacroRunner; import rene.zirkel.objects.AngleObject; import rene.zirkel.objects.AreaObject; import rene.zirkel.objects.ConstructionObject; import rene.zirkel.objects.EquationXYObject; import rene.zirkel.objects.ExpressionObject; import rene.zirkel.objects.FixedAngleObject; import rene.zirkel.objects.FixedCircleObject; import rene.zirkel.objects.FunctionObject; import rene.zirkel.objects.IntersectionObject; import rene.zirkel.objects.PointObject; import rene.zirkel.objects.PrimitiveCircleObject; import rene.zirkel.objects.PrimitiveLineObject; import rene.zirkel.objects.QuadricObject; import rene.zirkel.objects.SegmentObject; import rene.zirkel.objects.TextObject; import rene.zirkel.objects.TwoPointLineObject; import rene.zirkel.objects.VectorObject; /** * * @author erichake with addons by Dibs */ public class JSFunctions { static String[] allnames={"cm", "Input", "Entrée", "EntréeNombreEntier", "EntréeNombreDécimal", "Prompt", "Signaler", "Print", "Afficher", "afficher", "Println", "Afficherligne", "Shownames", "MontrerNoms", "Hidenames", "CacherNoms", "Hide", "Cacher", "Show", "Montrer", "Point", "PointOn", "PointSur", "ImplicitPlot", "TracéImplicite", "Intersection", "Intersection2", "Intersections", "MidPoint", "Milieu", "Symmetry", "SymétrieCentrale", "Line", "Droite", "Segment", "Circle", "Cercle", "Parallel", "Parallèle", "Perpendicular", "Perpendiculaire", "FixedCircle", "CercleRayon", "Move", "Déplacer", "X", "Y", "GetExpressionValue", "PrendreValeurExpression", "Ray", "DemiDroite", "Angle", "Polygon", "Polygone", "Quadric", "Quadrique", "CartesianFunction", "FonctionCartésienne", "ParametricFunction", "FonctionParamétrique", "SetColor", "MettreCouleur", "SetText", "MettreTexte", "SetThickness", "MettreEpaisseur", "SetFixed", "MettreFixe", "Vector", "Vecteur", "SetRGBColor", "MettreCouleurRVB", "SetShowName", "MettreMontrerNom", "SetShowValue", "MettreMontrerValeur", "SetFilled", "MettreRempli", "SetSolid", "MettreOpaque", "SetPartial", "MettrePartiel", "Expression", "Text", "Texte", "SetAlias", "MettreAlias", "SetMagneticObjects", "MettreObjetsMagnétiques", "AddMagneticObject", "AjouterObjetMagnétique", "SetMagneticRay", "MettreRayonMagnétique", "SetPointType", "MettreTypePoint", "InteractiveInput", "EntréeInteractive", "FixedSegment", "SegmentFixe", "SetHide", "MettreCaché", "Pause", "Delete", "Supprimer", "SetExpressionValue", "MettreValeurExpression", "Reflection", "SymétrieAxiale", "Translation", "PerpendicularBisector", "Médiatrice", "AngleBisector", "Bissectrice", "Circle3pts", "Cercle3pts", "Arc3pts", "FixedAngle", "AngleFixe", "Circle3", "Cercle3", "ExecuteMacro", "ExécuterMacro", "ExecuteMacroAsBuilt", "ExécuterMacroCommeDéfinie", "Alert", "Alerte", "Conditional", "Conditionnel", "Layer", "Calque", "GetRed", "PrendreRouge", "GetGreen", "PrendreVert", "GetBlue", "PrendreBleu", "PenDown", "CrayonBaissé", "SetRed", "MettreRouge", "SetGreen", "MettreVert", "SetBlue", "MettreBleu", "DPPoint", "DPLine", "DPSegment", "DPPerpendicular", "DPPerpendicularBisector", "DPMidPoint", "DPCircle", "DPReflexion", "DPSymmetry", "DPAngleBisector", "DPCommonPerpendicular", "DPRay", "getC", "getZC", "refreshZC", "rafraichirZC", "Load", "Origin", "Origine", "Extremity", "Extrémité", "GetText", "PrendreTexte", "ReflexAngle", "AngleRentrant", "Exists", "Existe", "SetIncrement", "MettreIncrément", "GetOpenFile", "PrendreFichierOuvert", "OrderedIntersection", "IntersectionOrdonnée", "SetMinOpen", "SetMinClosed", "SetMaxOpen", "SetMaxClosed","Distance", "Point3D", "X3D", "Y3D", "Z3D", "Distance3D", "getCONSOLE", "prendreCONSOLE", "Sphere", "Sphère", "FixedSphere", "SphèreRayon", "Projection3D", "Reflection3D", "Symétrie3DPlan", "Symmetry3D", "SymétrieCentrale3D", "Translation3D", "Circle3D", "Cercle3D", "FixedCircle3D", "CercleRayon3D", "Circle3D3pts", "Cercle3D3pts","SetIconSelection","IsIconSelected","AttacherTortue", "BaisserStylo","LeverStylo","Avancer","TournerGauche","TournerDroite","MontrerTortue","CacherTortue","OrienterTortue","VitesseTortue","Reculer","PivoterGauche","PivoterDroite","PivoterHaut","PivoterBas","Viser","Triangle","Quadrilatère","Quadrangle","FixTurtle","TurtleDown","TurtleUp","MoveForward","MoveBackward","TurnLeft", "TurnRight","RollLeft","RollRight","PitchUp","PitchDown","ShowTurtle","HideTurtle","OrientateTurtle","OrientateTowards","TurtleSpeed","Liberate","Libérer","getRealScript","getZZ","prendreZZ","Quadrilatère3D", "Quadrangle3D", "Polygone3D", "Polygon3D","ClicVirtuel"}; static PointObject ptTortue, pt3DTortue; static PointObject ptTortue2, pt3DTortue2; static PointObject ptSupport; static PointObject ptSupport2; static PointObject ptO; static PointObject ptO2; static PointObject ptO3; static VectorObject dirTortue; static VectorObject dirTortueVisu; static ExpressionObject longueurTortue, longueurTortue3D; static boolean styloBaisse, turtleIs3D; static double vitesseTortue = 100; static double nbSteps=1; static PointObject t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24; static Vector p1, p2, tete, p3, p4, cara; static AreaObject pp1, pp2, pp3, pp4, ttete, ccara; static PointObject pt3D0, pt3D1, pt3D2, pt3D3, pt3D1b, pt3D2b, pt3D3b, pt3DSupport, pt3DSupport01, pt3DSupport02, pt3DSupport03, t3D1, t3D2, t3D3, t3D4; static VectorObject dirTortue3D1, dirTortue3D2, dirTortue3D3, dirTortueVisu3D1, dirTortueVisu3D2, dirTortueVisu3D3; static Vector p3D; static AreaObject pp3D; static PointObject oldpt3D2, oldpt3D3, pt3D2bis, pt3D3bis, npoint; public static String[] getKeywords() { return allnames; } public static String AttacherTortue(String name) { pt3DTortue=(PointObject) getC().find(name); if (pt3DTortue!=null) { turtleIs3D=pt3DTortue.is3D(); synchronized (getC()) { if (turtleIs3D) { try { if (pt3D0==null) { longueurTortue3D=new ExpressionObject(getC(), 0, 0); longueurTortue3D.setDefaults(); longueurTortue3D.setHidden(true); longueurTortue3D.setName("kTortue3D"); longueurTortue3D.setPrompt(longueurTortue3D.getName()); styloBaisse = true; pt3D0=new PointObject(getC(),0,0); longueurTortue3D.setExpression("60/pixel", getC()); pt3D1=new PointObject(getC(),0,0); pt3D2=new PointObject(getC(),0,0); pt3D3=new PointObject(getC(),0,0); pt3D1b=new PointObject(getC(),0,0); pt3D2b=new PointObject(getC(),0,0); pt3D3b=new PointObject(getC(),0,0); dirTortue3D1= new VectorObject(getC(),pt3D0,pt3D1); dirTortue3D2= new VectorObject(getC(),pt3D0,pt3D2); dirTortue3D3= new VectorObject(getC(),pt3D0,pt3D3); pt3DSupport=new PointObject(getC(),0,0); pt3DSupport01=new PointObject(getC(),0,0); pt3DSupport02=new PointObject(getC(),0,0); pt3DSupport03=new PointObject(getC(),0,0); dirTortueVisu3D1= new VectorObject(getC(),pt3DSupport,pt3DSupport01); dirTortueVisu3D2= new VectorObject(getC(),pt3DSupport,pt3DSupport02); dirTortueVisu3D3= new VectorObject(getC(),pt3DSupport,pt3DSupport03); p3D= new Vector(); t3D1=new PointObject(getC(),0,0); t3D2=new PointObject(getC(),0,0); t3D3=new PointObject(getC(),0,0);; t3D4=new PointObject(getC(),0,0); pp3D = new AreaObject(getC(),p3D); pp3D.setDefaults(); pp3D.setFilled(true); pp3D.setSpecialColor(new Color(138,74,0)); } else { pt3D1=new PointObject(getC(),0,0); pt3D2=new PointObject(getC(),0,0); pt3D3=new PointObject(getC(),0,0); pt3D1b=new PointObject(getC(),0,0); pt3D2b=new PointObject(getC(),0,0); pt3D3b=new PointObject(getC(),0,0); } addObject(longueurTortue3D); addObject(pt3D0); addObject(pt3D1); addObject(pt3D2); addObject(pt3D3); addObject(pt3D1b); addObject(pt3D2b); addObject(pt3D3b); addObject(dirTortue3D1); addObject(dirTortue3D2); addObject(dirTortue3D3); addObject(pt3DSupport); addObject(pt3DSupport01); addObject(pt3DSupport02); addObject(pt3DSupport03); addObject(dirTortueVisu3D1); addObject(dirTortueVisu3D2); addObject(dirTortueVisu3D3); addObject(t3D1); addObject(t3D2); addObject(t3D3); addObject(pp3D); pt3D0.setIs3D(true); pt3D1.setIs3D(true); pt3D2.setIs3D(true); pt3D3.setIs3D(true); pt3D0.setFixed("0","0","0"); pt3D0.validate(); pt3D1.setFixed("1","0","0"); pt3D1.validate(); pt3D2.setFixed("0","1","0"); pt3D3.validate(); pt3D3.setFixed("0","0","1"); pt3D0.setHidden(true); pt3D1.setSuperHidden(true); pt3D2.setSuperHidden(true); pt3D3.setSuperHidden(true); pt3D1b.setSuperHidden(true); pt3D2b.setSuperHidden(true); pt3D3b.setSuperHidden(true); pt3D1b.setIs3D(true); pt3D2b.setIs3D(true); pt3D3b.setIs3D(true); pt3D1b.setFixed("1","0","0"); pt3D2b.setFixed("0","1","0"); pt3D3b.setFixed("0","0","1"); pt3DSupport.setIs3D(true); pt3DSupport01.setIs3D(true); pt3DSupport02.setIs3D(true); pt3DSupport03.setIs3D(true); t3D1.setIs3D(true); t3D2.setIs3D(true); t3D3.setIs3D(true); t3D4.setIs3D(true); dirTortue3D1.setDefaults(); dirTortue3D1.setHidden(true); dirTortue3D2.setDefaults(); dirTortue3D2.setHidden(true); dirTortue3D3.setDefaults(); dirTortue3D3.setHidden(true); dirTortueVisu3D1.setDefaults(); dirTortueVisu3D1.setHidden(true); dirTortueVisu3D2.setDefaults(); dirTortueVisu3D2.setHidden(true); dirTortueVisu3D3.setDefaults(); dirTortueVisu3D3.setHidden(true); pt3DTortue=(PointObject) getC().find(name); pt3DSupport.setSuperHidden(true); pt3DSupport.setFixed("x3D("+pt3DTortue.getName()+")","y3D("+pt3DTortue.getName()+")","z3D("+pt3DTortue.getName()+")"); pt3DSupport01.setSuperHidden(true); pt3DSupport01.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D1.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D1.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D1.getName()+")"); pt3DSupport02.setSuperHidden(true); pt3DSupport02.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D2.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D2.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D2.getName()+")"); pt3DSupport03.setSuperHidden(true); pt3DSupport03.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D3.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D3.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D3.getName()+")"); pt3DSupport.validate(); pt3DSupport01.validate(); pt3DSupport02.validate(); pt3DSupport03.validate(); dirTortueVisu3D1.validate(); dirTortueVisu3D2.validate(); dirTortueVisu3D3.validate(); p3D.add(pt3DSupport); t3D1.setDefaults(); t3D1.setSuperHidden(true); t3D1.setFixed("x3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D2.getName()+")","y3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D2.getName()+")","z3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D2.getName()+")"); p3D.add(t3D1); t3D2.setDefaults(); t3D2.setSuperHidden(true); t3D2.setFixed("x3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")","y3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")","z3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")"); p3D.add(t3D2); t3D3.setDefaults(); t3D3.setSuperHidden(true); t3D3.setFixed("x3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D2.getName()+")","y3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D2.getName()+")","z3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D2.getName()+")"); p3D.add(t3D3); t3D1.validate(); t3D2.validate(); t3D3.validate(); pp3D.validate(); pp3D.addConditional("solid",new Expression(pp3D.getName()+"<0",getC(),pp3D)); pp3D.addConditional("thick",new Expression(pp3D.getName()+"<0",getC(),pp3D)); } catch (Exception e) { return ""; } return name; } else { try { if (ptO==null) { longueurTortue=new ExpressionObject(getC(), 0, 0); longueurTortue.setDefaults(); longueurTortue.setHidden(true); longueurTortue.setName("kTortue"); longueurTortue.setPrompt(longueurTortue.getName()); styloBaisse = true; p1= new Vector(); t1=new PointObject(getC(),0,0); t2=new PointObject(getC(),0,0); t3=new PointObject(getC(),0,0); t4=new PointObject(getC(),0,0); pp1 = new AreaObject(getC(),p1); p2= new Vector(); t5=new PointObject(getC(),0,0); t6=new PointObject(getC(),0,0); pp2 = new AreaObject(getC(),p2); tete= new Vector(); t7=new PointObject(getC(),0,0); t8=new PointObject(getC(),0,0); t9=new PointObject(getC(),0,0); t10=new PointObject(getC(),0,0); t11=new PointObject(getC(),0,0); ttete = new AreaObject(getC(),tete); if (getC().find("turtleVttete")==null) {ttete.setName("turtleVttete");} p3= new Vector(); t12=new PointObject(getC(),0,0); t13=new PointObject(getC(),0,0); t14=new PointObject(getC(),0,0); pp3 = new AreaObject(getC(),p3); p4= new Vector(); t15=new PointObject(getC(),0,0); t16=new PointObject(getC(),0,0); t17=new PointObject(getC(),0,0); pp4 = new AreaObject(getC(),p4); cara= new Vector(); t18=new PointObject(getC(),0,0); t19=new PointObject(getC(),0,0); t20=new PointObject(getC(),0,0); t21=new PointObject(getC(),0,0); t22=new PointObject(getC(),0,0); t23=new PointObject(getC(),0,0); t24=new PointObject(getC(),0,0); ccara = new AreaObject(getC(),cara); if (getC().find("turtleVccara")==null) {ccara.setName("turtleVccara");} pp1.setDefaults(); pp1.setFilled(true); pp1.setSpecialColor(new Color(138,102,66)); pp2.setDefaults(); pp2.setFilled(true); pp2.setSpecialColor(new Color(138,102,66)); ttete.setDefaults(); ttete.setFilled(true); ttete.setSpecialColor(new Color(138,102,66)); pp3.setDefaults(); pp3.setFilled(true); pp3.setSpecialColor(new Color(138,102,66)); pp4.setDefaults(); pp4.setFilled(true); pp4.setSpecialColor(new Color(138,102,66)); ccara.setDefaults(); ccara.setFilled(true); ccara.setSpecialColor(new Color(82,139,139)); } try { longueurTortue.setExpression("60/pixel", getC()); } catch (final ConstructionException e) { return ""; } ptTortue=(PointObject) getC().find(name); // ptO=new PointObject(getC(),0,0); ptO2=new PointObject(getC(),1,0); dirTortue= new VectorObject(getC(),ptO,ptO2); ptSupport=new PointObject(getC(),0,0); ptSupport2=new PointObject(getC(),0,0); ptTortue2=new PointObject(getC(),0,0); dirTortueVisu= new VectorObject(getC(),ptSupport,ptSupport2); addObject(longueurTortue); ptO.setHidden(true); addObject(ptO); ptO.setFixed("0*x("+ptTortue.getName()+")","0"); // astuce... ptO2.setSuperHidden(true); addObject(ptO2); ptO2.setFixed("1","0*y("+ptTortue.getName()+")"); ptO.validate(); ptO2.validate(); dirTortue.validate(); dirTortue.setDefaults(); dirTortue.setHidden(true); addObject(dirTortue); ptSupport.setSuperHidden(true); addObject(ptSupport); ptSupport.setFixed("x("+ptTortue.getName()+")","y("+ptTortue.getName()+")"); ptSupport2.setSuperHidden(true); addObject(ptSupport2); ptSupport2.setFixed("x("+ptTortue.getName()+")+x("+dirTortue.getName()+")","y("+ptTortue.getName()+")+y("+dirTortue.getName()+")"); ptTortue2.setDefaults(); ptTortue2.setSuperHidden(true); addObject(ptTortue2); ptTortue2.setFixed("x("+ptTortue.getName()+")+x("+dirTortue.getName()+")","y("+ptTortue.getName()+")+y("+dirTortue.getName()+")"); ptTortue2.validate(); dirTortueVisu.validate(); dirTortueVisu.setDefaults(); dirTortueVisu.setHidden(true); addObject(dirTortueVisu); t1.setDefaults(); t1.setSuperHidden(true); addObject(t1); t1.setFixed("x("+ptSupport.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t1); t2.setDefaults(); t2.setSuperHidden(true); addObject(t2); t2.setFixed("x("+ptSupport.getName()+")-0.4*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.4*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t2); t3.setDefaults(); t3.setSuperHidden(true); addObject(t3); t3.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t3); addObject(pp1); t4.setDefaults(); t4.setSuperHidden(true); addObject(t4); t4.setFixed("x("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t4); t5.setDefaults(); t5.setSuperHidden(true); addObject(t5); t5.setFixed("x("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t5); t6.setDefaults(); t6.setSuperHidden(true); addObject(t6); t6.setFixed("x("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t6); addObject(pp2); t7.setDefaults(); t7.setSuperHidden(true); addObject(t7); t7.setFixed("x("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.1*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.1*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t7); t8.setDefaults(); t8.setSuperHidden(true); addObject(t8); t8.setFixed("x("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.15*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.15*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t8); t9.setDefaults(); t9.setSuperHidden(true); addObject(t9); t9.setFixed("x("+ptSupport.getName()+")+1.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+1.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")"); tete.add(t9); t10.setDefaults(); t10.setSuperHidden(true); addObject(t10); t10.setFixed("x("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.15*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.15*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t10); t11.setDefaults(); t11.setSuperHidden(true); addObject(t11); t11.setFixed("x("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.1*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.1*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t11); addObject(ttete); t12.setDefaults(); t12.setSuperHidden(true); addObject(t12); t12.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t12); t13.setDefaults(); t13.setSuperHidden(true); addObject(t13); t13.setFixed("x("+ptSupport.getName()+")+0.4*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")-0.4*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t13); t14.setDefaults(); t14.setSuperHidden(true); addObject(t14); t14.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t14); addObject(pp3); t15.setDefaults(); t15.setSuperHidden(true); addObject(t15); t15.setFixed("x("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t15); t16.setDefaults(); t16.setSuperHidden(true); addObject(t16); t16.setFixed("x("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t16); t17.setDefaults(); t17.setSuperHidden(true); addObject(t17); t17.setFixed("x("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t17); addObject(pp4); t18.setDefaults(); t18.setSuperHidden(true); addObject(t18); t18.setFixed("x("+ptSupport.getName()+")","y("+ptSupport.getName()+")"); cara.add(t18); t19.setDefaults(); t19.setSuperHidden(true); addObject(t19); t19.setFixed("x("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t19); t20.setDefaults(); t20.setSuperHidden(true); addObject(t20); t20.setFixed("x("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t20); t21.setDefaults(); t21.setSuperHidden(true); addObject(t21); t21.setFixed("x("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t21); t22.setDefaults(); t22.setSuperHidden(true); addObject(t22); t22.setFixed("x("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t22); t23.setDefaults(); t23.setSuperHidden(true); addObject(t23); t23.setFixed("x("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t23); t24.setDefaults(); t24.setSuperHidden(true); addObject(t24); t24.setFixed("x("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t24); addObject(ccara); } catch (Exception e) { return ""; } return name; } } } else { return(""); } } public static String FixTurtle(String name) { pt3DTortue=(PointObject) getC().find(name); if (pt3DTortue!=null) { turtleIs3D=pt3DTortue.is3D(); synchronized (getC()) { if (turtleIs3D) { try { if (pt3D0==null) { longueurTortue3D=new ExpressionObject(getC(), 0, 0); longueurTortue3D.setDefaults(); longueurTortue3D.setHidden(true); longueurTortue3D.setName("kTortue3D"); longueurTortue3D.setPrompt(longueurTortue3D.getName()); styloBaisse = true; pt3D0=new PointObject(getC(),0,0); longueurTortue3D.setExpression("60/pixel", getC()); pt3D1=new PointObject(getC(),0,0); pt3D2=new PointObject(getC(),0,0); pt3D3=new PointObject(getC(),0,0); pt3D1b=new PointObject(getC(),0,0); pt3D2b=new PointObject(getC(),0,0); pt3D3b=new PointObject(getC(),0,0); dirTortue3D1= new VectorObject(getC(),pt3D0,pt3D1); dirTortue3D2= new VectorObject(getC(),pt3D0,pt3D2); dirTortue3D3= new VectorObject(getC(),pt3D0,pt3D3); pt3DSupport=new PointObject(getC(),0,0); pt3DSupport01=new PointObject(getC(),0,0); pt3DSupport02=new PointObject(getC(),0,0); pt3DSupport03=new PointObject(getC(),0,0); dirTortueVisu3D1= new VectorObject(getC(),pt3DSupport,pt3DSupport01); dirTortueVisu3D2= new VectorObject(getC(),pt3DSupport,pt3DSupport02); dirTortueVisu3D3= new VectorObject(getC(),pt3DSupport,pt3DSupport03); p3D= new Vector(); t3D1=new PointObject(getC(),0,0); t3D2=new PointObject(getC(),0,0); t3D3=new PointObject(getC(),0,0);; t3D4=new PointObject(getC(),0,0); pp3D = new AreaObject(getC(),p3D); pp3D.setDefaults(); pp3D.setFilled(true); pp3D.setSpecialColor(new Color(138,74,0)); } else { pt3D1=new PointObject(getC(),0,0); pt3D2=new PointObject(getC(),0,0); pt3D3=new PointObject(getC(),0,0); pt3D1b=new PointObject(getC(),0,0); pt3D2b=new PointObject(getC(),0,0); pt3D3b=new PointObject(getC(),0,0); } addObject(longueurTortue3D); addObject(pt3D0); addObject(pt3D1); addObject(pt3D2); addObject(pt3D3); addObject(pt3D1b); addObject(pt3D2b); addObject(pt3D3b); addObject(dirTortue3D1); addObject(dirTortue3D2); addObject(dirTortue3D3); addObject(pt3DSupport); addObject(pt3DSupport01); addObject(pt3DSupport02); addObject(pt3DSupport03); addObject(dirTortueVisu3D1); addObject(dirTortueVisu3D2); addObject(dirTortueVisu3D3); addObject(t3D1); addObject(t3D2); addObject(t3D3); addObject(pp3D); pt3D0.setIs3D(true); pt3D1.setIs3D(true); pt3D2.setIs3D(true); pt3D3.setIs3D(true); pt3D0.setFixed("0","0","0"); pt3D0.validate(); pt3D1.setFixed("1","0","0"); pt3D1.validate(); pt3D2.setFixed("0","1","0"); pt3D3.validate(); pt3D3.setFixed("0","0","1"); pt3D0.setHidden(true); pt3D1.setSuperHidden(true); pt3D2.setSuperHidden(true); pt3D3.setSuperHidden(true); pt3D1b.setSuperHidden(true); pt3D2b.setSuperHidden(true); pt3D3b.setSuperHidden(true); pt3D1b.setIs3D(true); pt3D2b.setIs3D(true); pt3D3b.setIs3D(true); pt3D1b.setFixed("1","0","0"); pt3D2b.setFixed("0","1","0"); pt3D3b.setFixed("0","0","1"); pt3DSupport.setIs3D(true); pt3DSupport01.setIs3D(true); pt3DSupport02.setIs3D(true); pt3DSupport03.setIs3D(true); t3D1.setIs3D(true); t3D2.setIs3D(true); t3D3.setIs3D(true); t3D4.setIs3D(true); dirTortue3D1.setDefaults(); dirTortue3D1.setHidden(true); dirTortue3D2.setDefaults(); dirTortue3D2.setHidden(true); dirTortue3D3.setDefaults(); dirTortue3D3.setHidden(true); dirTortueVisu3D1.setDefaults(); dirTortueVisu3D1.setHidden(true); dirTortueVisu3D2.setDefaults(); dirTortueVisu3D2.setHidden(true); dirTortueVisu3D3.setDefaults(); dirTortueVisu3D3.setHidden(true); pt3DTortue=(PointObject) getC().find(name); pt3DSupport.setSuperHidden(true); pt3DSupport.setFixed("x3D("+pt3DTortue.getName()+")","y3D("+pt3DTortue.getName()+")","z3D("+pt3DTortue.getName()+")"); pt3DSupport01.setSuperHidden(true); pt3DSupport01.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D1.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D1.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D1.getName()+")"); pt3DSupport02.setSuperHidden(true); pt3DSupport02.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D2.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D2.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D2.getName()+")"); pt3DSupport03.setSuperHidden(true); pt3DSupport03.setFixed("x3D("+pt3DTortue.getName()+")+x3D("+dirTortue3D3.getName()+")","y3D("+pt3DTortue.getName()+")+y3D("+dirTortue3D3.getName()+")","z3D("+pt3DTortue.getName()+")+z3D("+dirTortue3D3.getName()+")"); pt3DSupport.validate(); pt3DSupport01.validate(); pt3DSupport02.validate(); pt3DSupport03.validate(); dirTortueVisu3D1.validate(); dirTortueVisu3D2.validate(); dirTortueVisu3D3.validate(); p3D.add(pt3DSupport); t3D1.setDefaults(); t3D1.setSuperHidden(true); t3D1.setFixed("x3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D2.getName()+")","y3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D2.getName()+")","z3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")+0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D2.getName()+")"); p3D.add(t3D1); t3D2.setDefaults(); t3D2.setSuperHidden(true); t3D2.setFixed("x3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")","y3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")","z3D("+pt3DSupport.getName()+")+0.8*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")"); p3D.add(t3D2); t3D3.setDefaults(); t3D3.setSuperHidden(true); t3D3.setFixed("x3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*x3D("+dirTortueVisu3D2.getName()+")","y3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*y3D("+dirTortueVisu3D2.getName()+")","z3D("+pt3DSupport.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D1.getName()+")-0.4*"+longueurTortue3D.getName()+"*z3D("+dirTortueVisu3D2.getName()+")"); p3D.add(t3D3); t3D1.validate(); t3D2.validate(); t3D3.validate(); pp3D.validate(); pp3D.addConditional("solid",new Expression(pp3D.getName()+"<0",getC(),pp3D)); pp3D.addConditional("thick",new Expression(pp3D.getName()+"<0",getC(),pp3D)); } catch (Exception e) { return ""; } return name; } else { try { if (ptO==null) { longueurTortue=new ExpressionObject(getC(), 0, 0); longueurTortue.setDefaults(); longueurTortue.setHidden(true); longueurTortue.setName("kTortue"); longueurTortue.setPrompt(longueurTortue.getName()); styloBaisse = true; p1= new Vector(); t1=new PointObject(getC(),0,0); t2=new PointObject(getC(),0,0); t3=new PointObject(getC(),0,0); t4=new PointObject(getC(),0,0); pp1 = new AreaObject(getC(),p1); p2= new Vector(); t5=new PointObject(getC(),0,0); t6=new PointObject(getC(),0,0); pp2 = new AreaObject(getC(),p2); tete= new Vector(); t7=new PointObject(getC(),0,0); t8=new PointObject(getC(),0,0); t9=new PointObject(getC(),0,0); t10=new PointObject(getC(),0,0); t11=new PointObject(getC(),0,0); ttete = new AreaObject(getC(),tete); if (getC().find("turtleVttete")==null) {ttete.setName("turtleVttete");} p3= new Vector(); t12=new PointObject(getC(),0,0); t13=new PointObject(getC(),0,0); t14=new PointObject(getC(),0,0); pp3 = new AreaObject(getC(),p3); p4= new Vector(); t15=new PointObject(getC(),0,0); t16=new PointObject(getC(),0,0); t17=new PointObject(getC(),0,0); pp4 = new AreaObject(getC(),p4); cara= new Vector(); t18=new PointObject(getC(),0,0); t19=new PointObject(getC(),0,0); t20=new PointObject(getC(),0,0); t21=new PointObject(getC(),0,0); t22=new PointObject(getC(),0,0); t23=new PointObject(getC(),0,0); t24=new PointObject(getC(),0,0); ccara = new AreaObject(getC(),cara); if (getC().find("turtleVccara")==null) {ccara.setName("turtleVccara");} pp1.setDefaults(); pp1.setFilled(true); pp1.setSpecialColor(new Color(138,102,66)); pp2.setDefaults(); pp2.setFilled(true); pp2.setSpecialColor(new Color(138,102,66)); ttete.setDefaults(); ttete.setFilled(true); ttete.setSpecialColor(new Color(138,102,66)); pp3.setDefaults(); pp3.setFilled(true); pp3.setSpecialColor(new Color(138,102,66)); pp4.setDefaults(); pp4.setFilled(true); pp4.setSpecialColor(new Color(138,102,66)); ccara.setDefaults(); ccara.setFilled(true); ccara.setSpecialColor(new Color(82,139,139)); } try { longueurTortue.setExpression("60/pixel", getC()); } catch (final ConstructionException e) { return ""; } ptTortue=(PointObject) getC().find(name); // ptO=new PointObject(getC(),0,0); ptO2=new PointObject(getC(),1,0); dirTortue= new VectorObject(getC(),ptO,ptO2); ptSupport=new PointObject(getC(),0,0); ptSupport2=new PointObject(getC(),0,0); ptTortue2=new PointObject(getC(),0,0); dirTortueVisu= new VectorObject(getC(),ptSupport,ptSupport2); addObject(longueurTortue); ptO.setHidden(true); addObject(ptO); ptO.setFixed("0*x("+ptTortue.getName()+")","0"); // astuce... ptO2.setSuperHidden(true); addObject(ptO2); ptO2.setFixed("1","0*y("+ptTortue.getName()+")"); ptO.validate(); ptO2.validate(); dirTortue.validate(); dirTortue.setDefaults(); dirTortue.setHidden(true); addObject(dirTortue); ptSupport.setSuperHidden(true); addObject(ptSupport); ptSupport.setFixed("x("+ptTortue.getName()+")","y("+ptTortue.getName()+")"); ptSupport2.setSuperHidden(true); addObject(ptSupport2); ptSupport2.setFixed("x("+ptTortue.getName()+")+x("+dirTortue.getName()+")","y("+ptTortue.getName()+")+y("+dirTortue.getName()+")"); ptTortue2.setDefaults(); ptTortue2.setSuperHidden(true); addObject(ptTortue2); ptTortue2.setFixed("x("+ptTortue.getName()+")+x("+dirTortue.getName()+")","y("+ptTortue.getName()+")+y("+dirTortue.getName()+")"); ptTortue2.validate(); dirTortueVisu.validate(); dirTortueVisu.setDefaults(); dirTortueVisu.setHidden(true); addObject(dirTortueVisu); t1.setDefaults(); t1.setSuperHidden(true); addObject(t1); t1.setFixed("x("+ptSupport.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t1); t2.setDefaults(); t2.setSuperHidden(true); addObject(t2); t2.setFixed("x("+ptSupport.getName()+")-0.4*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.4*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t2); t3.setDefaults(); t3.setSuperHidden(true); addObject(t3); t3.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p1.add(t3); addObject(pp1); t4.setDefaults(); t4.setSuperHidden(true); addObject(t4); t4.setFixed("x("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t4); t5.setDefaults(); t5.setSuperHidden(true); addObject(t5); t5.setFixed("x("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t5); t6.setDefaults(); t6.setSuperHidden(true); addObject(t6); t6.setFixed("x("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p2.add(t6); addObject(pp2); t7.setDefaults(); t7.setSuperHidden(true); addObject(t7); t7.setFixed("x("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.1*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.1*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t7); t8.setDefaults(); t8.setSuperHidden(true); addObject(t8); t8.setFixed("x("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.15*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.15*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t8); t9.setDefaults(); t9.setSuperHidden(true); addObject(t9); t9.setFixed("x("+ptSupport.getName()+")+1.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+1.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")"); tete.add(t9); t10.setDefaults(); t10.setSuperHidden(true); addObject(t10); t10.setFixed("x("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.15*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.9*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.15*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t10); t11.setDefaults(); t11.setSuperHidden(true); addObject(t11); t11.setFixed("x("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.1*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.75*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.1*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); tete.add(t11); addObject(ttete); t12.setDefaults(); t12.setSuperHidden(true); addObject(t12); t12.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t12); t13.setDefaults(); t13.setSuperHidden(true); addObject(t13); t13.setFixed("x("+ptSupport.getName()+")+0.4*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")-0.4*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t13); t14.setDefaults(); t14.setSuperHidden(true); addObject(t14); t14.setFixed("x("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p3.add(t14); addObject(pp3); t15.setDefaults(); t15.setSuperHidden(true); addObject(t15); t15.setFixed("x("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t15); t16.setDefaults(); t16.setSuperHidden(true); addObject(t16); t16.setFixed("x("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.5*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.7*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.5*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t16); t17.setDefaults(); t17.setSuperHidden(true); addObject(t17); t17.setFixed("x("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.2*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.65*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.2*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); p4.add(t17); addObject(pp4); t18.setDefaults(); t18.setSuperHidden(true); addObject(t18); t18.setFixed("x("+ptSupport.getName()+")","y("+ptSupport.getName()+")"); cara.add(t18); t19.setDefaults(); t19.setSuperHidden(true); addObject(t19); t19.setFixed("x("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t19); t20.setDefaults(); t20.setSuperHidden(true); addObject(t20); t20.setFixed("x("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t20); t21.setDefaults(); t21.setSuperHidden(true); addObject(t21); t21.setFixed("x("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")+0.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")-0.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t21); t22.setDefaults(); t22.setSuperHidden(true); addObject(t22); t22.setFixed("x("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.05*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.8*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.05*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t22); t23.setDefaults(); t23.setSuperHidden(true); addObject(t23); t23.setFixed("x("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.6*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t23); t24.setDefaults(); t24.setSuperHidden(true); addObject(t24); t24.setFixed("x("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")-0.35*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")","y("+ptSupport.getName()+")+0.3*"+longueurTortue.getName()+"*y("+dirTortueVisu.getName()+")+0.35*"+longueurTortue.getName()+"*x("+dirTortueVisu.getName()+")"); cara.add(t24); addObject(ccara); } catch (Exception e) { return ""; } return name; } } } else { return(""); } } public static boolean BaisserStylo() { styloBaisse = true; return true; } public static boolean TurtleDown() { styloBaisse = true; return true; } public static boolean LeverStylo() { styloBaisse = false; return false; } public static boolean TurtleUp() { styloBaisse = false; return false; } public static String[] Avancer(String ptName, String segtName, String di) throws Exception { PointObject pt=null; SegmentObject so=null; String[] ptSegmt=new String[2]; synchronized (getC()) { if (segtName.equals("undefined")) { di=ptName; segtName=""; ptName=""; } else if (di.equals("undefined")) { di=segtName; segtName=""; } if (turtleIs3D) { try { pt=new PointObject(getC(), 0, 0); pt.setIs3D(true); pt.setFixed("x3D("+pt3DTortue.getName()+")","y3D("+pt3DTortue.getName()+")","z3D("+pt3DTortue.getName()+")"); pt.validCoordinates(); pt.setDefaults(); pt.setShowValue(false); pt.setShowName(false); pt.setType(3); if (!ptName.equals("")) { pt.setName(parseVariables(ptName)); } addObject(pt); pt3DSupport.setFixed("x3D("+pt.getName()+")","y3D("+pt.getName()+")","z3D("+pt.getName()+")"); pt3DSupport.validCoordinates(); pt3DSupport01.setFixed("x3D("+pt3DSupport.getName()+")+x3D("+dirTortue3D1.getName()+")","y3D("+pt3DSupport.getName()+")+y3D("+dirTortue3D1.getName()+")","z3D("+pt3DSupport.getName()+")+z3D("+dirTortue3D1.getName()+")"); pt3DSupport01.validCoordinates(); pt3DSupport02.setFixed("x3D("+pt3DSupport.getName()+")+x3D("+dirTortue3D2.getName()+")","y3D("+pt3DSupport.getName()+")+y3D("+dirTortue3D2.getName()+")","z3D("+pt3DSupport.getName()+")+z3D("+dirTortue3D2.getName()+")"); pt3DSupport02.validCoordinates(); pt3DSupport03.setFixed("x3D("+pt3DSupport.getName()+")+x3D("+dirTortue3D3.getName()+")","y3D("+pt3DSupport.getName()+")+y3D("+dirTortue3D3.getName()+")","z3D("+pt3DSupport.getName()+")+z3D("+dirTortue3D3.getName()+")"); pt3DSupport03.validCoordinates(); if (styloBaisse) { so=new SegmentObject(getC(),pt3DTortue,pt); so.validate(); so.setDefaults(); if (!segtName.equals("")) { so.setName(parseVariables(segtName)); } addObject(so); } else { pt.setHidden(true); } for (int l=1;l100) { theSpeed=100; } } nbSteps= Math.floor(99/theSpeed)+1; } } public static void TurtleSpeed(String vitesse){ synchronized (getC()) { double theSpeed = Double.parseDouble(vitesse); if (theSpeed<0.01) { theSpeed=0.01; } else { if (theSpeed>100) { theSpeed=100; } } nbSteps= Math.floor(99/theSpeed)+1; } } private static void setJSO(ConstructionObject o) { ScriptThread th=(ScriptThread) Thread.currentThread(); th.setJSO(o); } private static ConstructionObject getJSO() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getJSO(); } private static boolean isValidII() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.isValidII(); } private static void paint() { ScriptThread th=(ScriptThread) Thread.currentThread(); th.getZC().repaint(); } private static void addObject(ConstructionObject o) { ScriptThread th=(ScriptThread) Thread.currentThread(); th.getC().add(o); th.getZC().update_distant(o, 1); } public static void refreshZC() { ScriptThread th=(ScriptThread) Thread.currentThread(); th.getZC().dovalidate(); th.getZC().repaint(); } public static void rafraichirZC() { ScriptThread th=(ScriptThread) Thread.currentThread(); th.getZC().dovalidate(); th.getZC().repaint(); } public static Construction getC() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getC(); } public static ZirkelCanvas getZC() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getZC(); } public static String getRealScript() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getSCRIPT(); } public static String getZZ() { ScriptThread th=(ScriptThread) Thread.currentThread(); String bibop=th.getSCRIPT(); bibop=bibop.replace("=","⟵"); bibop=bibop.replace("⟵⟵","="); bibop=bibop.replace("!⟵","≠"); bibop=bibop.replace("<⟵","≤"); bibop=bibop.replace(">⟵","≥"); bibop=bibop.replace("Afficherligne","Afficher"); return bibop; } public static String prendreZZ() { ScriptThread th=(ScriptThread) Thread.currentThread(); String bibop=th.getSCRIPTi(); bibop=bibop.replace("=","⟵"); bibop=bibop.replace("⟵⟵","="); bibop=bibop.replace("!⟵","≠"); bibop=bibop.replace("<⟵","≤"); bibop=bibop.replace(">⟵","≥"); bibop=bibop.replace("Println","Afficher"); bibop=bibop.replace("Print","Afficher"); return bibop; } private static ScriptThread getTHREAD() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th; } private static ScriptableObject getSCOPE() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getSCOPE(); } public static JSOuputConsole getCONSOLE() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getCONSOLE(); } public static JSOuputConsole prendreCONSOLE() { ScriptThread th=(ScriptThread) Thread.currentThread(); return th.getCONSOLE(); } public static boolean SetIconSelection(String iconname, boolean sel) { return PaletteManager.setSelected_with_clic2(iconname, sel); } public static boolean ClicVirtuel(String iconname, boolean sel) { return PaletteManager.setSelected_with_clic2(iconname, sel); } public static boolean IsIconSelected(String iconname) { return PaletteManager.isSelected(iconname); } /** * Read a file an return is content as a string.
*
* This function will be useful in javascript context.
* One will be able, for instance, to write inside a CaRScript :
* eval(Load("mytools.js"));
* This will behave as if the file "mytools.js" had been imported.
* The objects of "mytools.js" will be accessible within the CaRScript.
* * Load is more versatile than just an import function.
* Indeed, you have the opportunity to make some text processing * after loading and before evaluating :
*MyTools = Load("mytools.js");
*MyTools = doSomeModificationsTo(MyTools); // apply some regexps or whatever
*eval(Mytools);
* * @param fic * @return The read text */ public static String Load(String fic) { String FS=System.getProperty("file.separator"); String myfic=Global.getHomeDirectory()+"scripts"+FS+fic.replace("/", FS); if (!new File(myfic).exists()) { myfic=FileName.path(JZirkelCanvas.getFileName())+FS+fic.replace("/", FS); } String r; String s=""; boolean firstLine=true; try { java.io.BufferedReader f=new java.io.BufferedReader(new java.io.FileReader(myfic)); try { while ((r=f.readLine())!=null) { s=(firstLine==true)?r:s+System.getProperty("line.separator")+r; firstLine=false; } f.close(); return s; } catch (java.io.IOException e) { return s; } } catch (java.io.FileNotFoundException e) { return ""; } } private static String parseVariables(String s) { String origin; String endtxt=s.replaceAll("([0-9]+)e([0-9]+)", "$1E$2"); do { origin=endtxt; StringBuffer sb1=new StringBuffer(); Pattern pxy=Pattern.compile("(x|y)_(\\w*)", Pattern.CASE_INSENSITIVE); Matcher m=pxy.matcher(origin); while (m.find()) { Object x=getSCOPE().get(m.group(2), getSCOPE()); if (x!=Scriptable.NOT_FOUND) { m.appendReplacement(sb1, m.group(1)+"("+Context.toString(x)+")"); } } m.appendTail(sb1); m.reset(); StringBuffer sb2=new StringBuffer(); Pattern pexp=Pattern.compile("_(\\w*)", Pattern.CASE_INSENSITIVE); m=pexp.matcher(sb1.toString()); while (m.find()) { Object x=getSCOPE().get(m.group(1), getSCOPE()); if (x!=Scriptable.NOT_FOUND) { m.appendReplacement(sb2, Context.toString(x)); } } m.appendTail(sb2); m.reset(); endtxt=sb2.toString(); } while (!(origin.equals(endtxt))); return endtxt; } static public String Loc(final String s) { return Global.Loc("JSerror."+s); } static public String LastNObjectsName(int N){ if(N==0){ return ""; } String names; if(getC().lastButN(0)!=null){ names = getC().lastButN(0).getName(); } else { names = ""; } for(int i=1; iNote : It's possible to change this property in one step for * multiple object. *
Example : SetColor("A,B,c1,E1","cyan") will give the "cyan" color * to the objects A, B, c1 and E1 * @param name Name of the object you want to change color * @param col Name of the color. It can be "green", "blue", "brown", "cyan", "red" or "black". */ static public void SetColor(String name, String col) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("color("+col+"," + name1 + ")"); } } static public void MettreCouleur(String name, String col) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("color("+col+"," + name1 + ")"); } } /** *Set the shape of a point. It has no effect if the object is not a point. *
Note : It's possible to change this property in one step for * multiple points. *
Example : SetPointType("A,B,E,F","square") will give the "square" shape * to the points A, B, E and F * @param name Name of the point you want to change shape * @param type Name of the shape. It can be "square", "circle", "diamond", "point", "cross", "dcross". */ static public void SetPointType(String name, String type) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("type("+type+"," + name1 + ")"); } } static public void MettreTypePoint(String name, String type) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("type("+type+"," + name1 + ")"); } } /** * Set the RGB color of an object using 3 integer numbers in [0..255]. *
Note : It's possible to change this property in one step for * multiple object. *
Example : SetColor("A,B,c1",120,40,245) will give the same color * to the objects A, B and c1. This color is defined by r=120, g=40 and b=245. * @param name Name of the object you want to change color * @param r Red value (integer in [0..255] * @param g Green value (integer in [0..255] * @param b Blue value (integer in [0..255] */ static public void SetRGBColor(String name, String r, String g, String b) { // Color mycolor=new Color(r, g, b); String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { // o.setSpecialColor(mycolor); o.setSpecialColor(r,g,b); } } // getZC().repaint(); // validate(); // paint() } static public void MettreCouleurRVB(String name, String r, String g, String b) { // Color mycolor=new Color(r, g, b); String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { // o.setSpecialColor(mycolor); o.setSpecialColor(r,g,b); } } // getZC().repaint(); // validate(); // paint() } /** * Set the thickness of an object. *
Note : It's possible to change this property in one step for * multiple objects. *
Example : SetThickness("A,B,c1,l1","thick") will give the "thick" aspect * to the objects A, B, c1 and l1 * @param name Name of the point you want to change shape * @param thc Name of the thickness. It can be "thick", "normal" and "thin". */ static public void SetThickness(String name, String thc) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("thickness("+thc+"," + name1 + ")"); } } static public void MettreEpaisseur(String name, String thc) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("thickness("+thc+"," + name1 + ")"); } } /** * Set the alias name of an object. *
Note : It's possible to change this property in one step for * multiple objects. *
Example : SetAlias("A,B,c1,l1","My beautiful object") * will give the "My beautiful object" alias name to the objects A, B, c1 and l1 * @param name Name of the point you want to change alias name. * @param alias Alias name. */ static public void SetAlias(String name, String alias) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setAlias(parseVariables(alias)); } } } static public void MettreAlias(String name, String alias) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setAlias(parseVariables(alias)); } } } /** * Set the increment of a point object. *
Note : It's possible to change this property in one step for * multiple points. *
Example : SetIncrement("A,B,C",0.1) * will set the increment of A, B, and C * @param name Name of the point you want to set the increment. * @param delta */ static public void SetIncrement(String name, double delta) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o instanceof PointObject) { o.setIncrement(delta); } } } static public void MettreIncrément(String name, double delta) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o instanceof PointObject) { o.setIncrement(delta); } } } /** * Set the standard magnetic attraction lenght of a point * @param name Name of a point * @param ray Attraction lenght, in pixels (number or expression) * @see #SetMagneticObjects * @see #AddMagneticObject */ static public void SetMagneticRay(String name, String ray) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.setMagnetRayExp(parseVariables(ray)); refreshZC(); } static public void MettreRayonMagnétique(String name, String ray) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.setMagnetRayExp(parseVariables(ray)); refreshZC(); } /** * Set the objects that will magnetize a given point *
Example : SetMagneticObjects("P","c1,d1,A") will * make the point P attracted by the objects c1, d1 and A. *
It's possible to define exceptions using the ":" separator. * If, for instance, objectlist contains "A,E,c1:20,l1" and the attraction * field is defined by 50 pixels, objects "A", "E" and "l1" have an attraction * radius of 50 pixels, but the object c1 will have an attraction radius of 20 pixels. * @param name Name of a point * @param objectlist List of objects * @see #AddMagneticObject * @see #SetMagneticRay */ static public void SetMagneticObjects(String name, String objectlist) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.setMagnetObjects(parseVariables(objectlist)); } static public void MettreObjetsMagnétiques(String name, String objectlist) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.setMagnetObjects(parseVariables(objectlist)); } /** * Add an object to the list of magnetic objects of a given point. * @param name Name of the point * @param object Object to add to the magnetic point list * @see #SetMagneticObjects * @see #SetMagneticRay */ static public void AddMagneticObject(String name, String object) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.addMagnetObject(parseVariables(object)); } static public void AjouterObjetMagnétique(String name, String object) { ConstructionObject o=getC().find(name); if ((o==null)||(!(o instanceof PointObject))) { return; } PointObject pt=(PointObject) o; pt.addMagnetObject(parseVariables(object)); } /** * Fix or unfix an object in the CaRMetal current window. A fixed object * can't be moved with the mouse. *
Note : It's possible to change this property in one step for * multiple objects. *
Example : SetFixed("A,B,c1,l1",true) * will fix the objects A, B, c1 and l1 in the CaRMetal current window. * @param name Name of the object * @param bool "true" value to fix the object, "false" to unfix it. */ static public void SetFixed(String name, boolean bool) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFixed(bool); } } } static public void MettreFixe(String name, boolean bool) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFixed(bool); } } } static public void Liberate(String name) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFixed(false); } } } static public void Libérer(String name) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFixed(false); } } } /** * Shows or hide the name of an object (or multiple objects). *
Example : SetShowName("A,B,c1,l1",true) * will shows the names of objects A, B, c1 and l1. * @param name Name(s) of object. * @param bool "true" to show name, and "false" to hide it. */ static public void SetShowName(String name, boolean bool) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setShowName(bool); } } } static public void MettreMontrerNom(String name, boolean bool) { String[] names=parseVariables(name).split(","); for(String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setShowName(bool); } } } /** * Shows or hide the value of an object (or multiple objects). *
Example : SetShowValue("A,B,c1,l1",true) * will shows the value of objects A, B, c1 and l1. * @param name Name(s) of object. * @param bool "true" to show value, and "false" to hide it. */ static public void SetShowValue(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setShowValue(bool); } } } static public void MettreMontrerValeur(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setShowValue(bool); } } } /** * Some objects can be filled (circles, polygons, etc...). This will * fill or unfill an object (or multiple objects). *
Example : SetFilled("A,B,c1,l1",true) * will fill objects A, B, c1 and l1. * @param name Name(s) of object. * @param bool "true" to fill objects, and "false" to unfill it. */ static public void SetFilled(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFilled(bool); } } } static public void MettreRempli(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setFilled(bool); } } } static public void SetSolid(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (int i=0; iExample : SetPartial("A,B,c1,l1",true) * will draw partially objects A, B, c1 and l1. * @param name Name(s) of object. * @param bool "true" to draw partially, and "false" to draw completly. */ static public void SetPartial(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setPartial(bool); getC().updateCircleDep(); } } } static public void MettrePartiel(String name, boolean bool) { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (o!=null) { o.setPartial(bool); getC().updateCircleDep(); } } } /** *After calling this command, names of new objects will be displayed. */ static public void Shownames() { cm("shownames"); } static public void MontrerNoms() { cm("shownames"); } /** *After calling this command, names of new objects will not be displayed. */ static public void Hidenames() { cm("hidenames"); } static public void CacherNoms() { cm("hidenames"); } /** * Hides an object (or multiple objects). *
Example : Hide("A,B,c1,l1") * will hide objects A, B, c1 and l1. * @param name Name(s) of object(s). */ static public void Hide(String name) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("hide(true," + name1 + ")"); } paint(); } static public void Cacher(String name) { String[] names=parseVariables(name).split(","); for(String name1 : names) { c("hide(true," + name1 + ")"); } paint(); } static public void SetHide(String name, boolean b) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("hide("+b+"," + name1 + ")"); } paint(); } static public void MettreCaché(String name, boolean b) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("hide("+b+"," + name1 + ")"); } paint(); } /** * Shows an object (or multiple objects). *
Example : Show("A,B,c1,l1") * will show objects A, B, c1 and l1. * @param name Name(s) of object(s). */ static public void Show(String name) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("hide(false," + name1 + ")"); } paint(); } static public void Montrer(String name) { String[] names=parseVariables(name).split(","); for (String name1 : names) { c("hide(false," + name1 + ")"); } paint(); } // static public void Delete(String name) { // String[] names=parseVariables(name).split(","); // for (int i=0; iFrom javascript, you can also do something like this : *
    *
  1. a=Point("",1,2)
  2. *
  3. b=Point("",-2,3)
  4. *
  5. m=4
  6. *
  7. c=Point("","(x_a+x_b)/_m","(y_a+y_b)/_m")
  8. *
* The "_" symbol means that javascript must use the content of variables. * For example The string "_m" will be replaced by "4" (line 3).
Another * "shortcut" : if, for example, a contains "P1" (the real name of the point * created by step 1), the string x_a is equivalent to the string "x(P1)". * @param name Name of the point (suggestion) * @param x x-coordinate (number or expression) * @param y y-coordinate (number or expression) * @return Name of the created point * @throws java.lang.Exception */ static public String Point(String name, String x, String y) throws Exception { PointObject pt=null; synchronized (getC()) { if (x.equals("undefined")) { double xx=getC().getX()+2*Math.random()*getC().getW()-getC().getW(); double yy=getC().getY()-Math.random()*getC().getH()+getC().getH()/2; x=""+xx; y=""+yy; if (name.equals("undefined")) { name=""; } } else if (y.equals("undefined")) { y=x; x=name; name=""; } try { pt=new PointObject(getC(), Math.round(Double.valueOf(x)*1E13)/1E13, Math.round(Double.valueOf(y)*1E13)/1E13); } catch (NumberFormatException e) { try { pt=new PointObject(getC(), 0, 0); pt.setFixed(parseVariables(x), parseVariables(y)); pt.validCoordinates(); } catch (Exception ex) { throw new Exception(Loc("pointcoords")); } } pt.setDefaults(); if (!name.equals("")) { pt.setName(parseVariables(name)); } pt.validate(); addObject(pt); return pt.getName(); } } /** * @author Dibs * */ static public String Point3D(String name, String x, String y, String z) throws Exception { if (!getZC().is3D()) return ""; PointObject pt=null; synchronized (getC()) { if (x.equals("undefined")) { double xx=getC().getX()+2*Math.random()*getC().getW()-getC().getW(); double yy=getC().getY()-Math.random()*getC().getH()+getC().getH()/2; try { double xO=getC().find("O").getX(), yO = getC().find("O").getY(); double x3DO=getC().find("O").getX(); double y3DO=getC().find("O").getY(); double xx3D = Math.sin(Math.toRadians(getC().find("E10").getValue()))*(xx-xO)-Math.sin(Math.toRadians(getC().find("E11").getValue()))*Math.cos(Math.toRadians(getC().find("E10").getValue()))*(yy-yO); double yy3D = Math.cos(Math.toRadians(getC().find("E10").getValue()))*(xx-xO)+Math.sin(Math.toRadians(getC().find("E11").getValue()))*Math.sin(Math.toRadians(getC().find("E10").getValue()))*(yy-yO); double zz3D = Math.cos(Math.toRadians(getC().find("E11").getValue()))*(yy-yO); if (Math.abs(xx3D)<1e-16) { xx3D=0; } if (Math.abs(yy3D)<1e-16) { yy3D=0; } if (Math.abs(zz3D)<1e-16) { zz3D=0; } x=""+xx3D; y=""+yy3D; z=""+zz3D; } catch (final Exception f) { x=""+Math.random(); y=""+Math.random(); z=""+Math.random(); } if (name.equals("undefined")) { name=""; } } else if (z.equals("undefined")) { z=y; y=x; x=name; name=""; } try { double x1 = Math.round(Double.valueOf(x)*1E13)/1E13; double y1 =Math.round(Double.valueOf(y)*1E13)/1E13; double z1 =Math.round(Double.valueOf(z)*1E13)/1E13; pt=new PointObject(getC(), 0, 0); pt.setFixed("x(O)+("+x1+")*(x(X)-x(O))+("+y1+")*(x(Y)-x(O))+("+z1+")*(x(Z)-x(O))", "y(O)+("+x1+")*(y(X)-y(O))+("+y1+")*(y(Y)-y(O))+("+z1+")*(y(Z)-y(O))"); pt.setIs3D(true); pt.setX3D(x1); pt.setY3D(y1); pt.setZ3D(z1); } catch (Exception e) { try { pt=new PointObject(getC(), 0, 0); pt.setFixed(x,y,z); pt.setIs3D(true); pt.validCoordinates3D(); pt.setFixed("x(O)+("+parseVariables(x)+")*(x(X)-x(O))+("+parseVariables(y)+")*(x(Y)-x(O))+("+parseVariables(z)+")*(x(Z)-x(O))", "y(O)+("+parseVariables(x)+")*(y(X)-y(O))+("+parseVariables(y)+")*(y(Y)-y(O))+("+parseVariables(z)+")*(y(Z)-y(O))"); pt.validCoordinates(); } catch (Exception ex) { throw new Exception(Loc("pointcoords")); } } pt.setDefaults(); if (!name.equals("")) { pt.setName(parseVariables(name)); } pt.setColorType(ConstructionObject.NORMAL); pt.setShowName(false); pt.setShowValue(false); pt.validate(); addObject(pt); return pt.getName(); } } /** * Set or Create a bounded point * @param name Name of the bound point * @param obj Name of the object * @return Name of the set or created point */ static public String PointOn(String name, String obj) { PointObject pt; synchronized (getC()) { if (obj.equals("undefined")) { obj=parseVariables(name);//à tester... pt=new PointObject(getC(), 0, 0); pt.setDefaults(); addObject(pt); } else { ConstructionObject co=getC().find(name); if (co==null) { pt=new PointObject(getC(), name); pt.setDefaults(); addObject(pt); } else { pt=(PointObject) co; } } pt.setBound(obj); pt.setUseAlpha(true); //pt will keep his barycentric coordinates relative to obj //to avoid the bound point being too near of an existing point final Enumeration e=getC().elements(); while (e.hasMoreElements()) { ConstructionObject c=(ConstructionObject) e.nextElement(); if (c instanceof PointObject) { if ((pt.getX()-c.getX()<0.1)&&(pt.getY()-c.getY()<0.1)) { pt.setXY(pt.getX()+Math.random()*2-1, pt.getY()+Math.random()*2-1); break; } } } return pt.getName(); } } static public String PointSur(String name, String obj) { PointObject pt; synchronized (getC()) { if (obj.equals("undefined")) { obj=parseVariables(name);//à tester... pt=new PointObject(getC(), 0, 0); pt.setDefaults(); addObject(pt); } else { ConstructionObject co=getC().find(name); if (co==null) { pt=new PointObject(getC(), name); pt.setDefaults(); addObject(pt); } else { pt=(PointObject) co; } } pt.setBound(obj); pt.setUseAlpha(true); //pt will keep his barycentric coordinates relative to obj //to avoid the bound point being too near of an existing point final Enumeration e=getC().elements(); while (e.hasMoreElements()) { ConstructionObject c=(ConstructionObject) e.nextElement(); if (c instanceof PointObject) { if ((pt.getX()-c.getX()<0.1)&&(pt.getY()-c.getY()<0.1)) { pt.setXY(pt.getX()+Math.random()*2-1, pt.getY()+Math.random()*2-1); break; } } } return pt.getName(); } } /** * Create the midpoint of two existing points * @param name Name of the midpoint * @param a Name of first point * @param b Name of second point * @return the midpoint name */ static public String MidPoint(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Midpoint"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } return LastNObjectsName(1); } } static public String Milieu(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Midpoint"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } return LastNObjectsName(1); } } /** * Reflects the point p with line d * @param name Name of the Symmetric * @param l Reflection line * @param p Point to reflect * @return the reflection point name * @throws java.lang.Exception */ static public String Reflection(String name, String l, String p) throws Exception { synchronized (getC()) { if (p.equals("undefined")) { p=l; l=name; name=""; } l=parseVariables(l); p=parseVariables(p); if (name.equals("")) { c("@builtin@/syma("+l+","+p+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/syma("+l+","+p+")"); } return LastNObjectsName(1); } } static public String SymétrieAxiale(String name, String l, String p) throws Exception { synchronized (getC()) { if (p.equals("undefined")) { p=l; l=name; name=""; } l=parseVariables(l); p=parseVariables(p); if (name.equals("")) { c("@builtin@/syma("+l+","+p+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/syma("+l+","+p+")"); } return LastNObjectsName(1); } } /** * Translate the point p with vector ab * @param name Name of the Translated point * @param a first point of the vector * @param b second point of the vector * @param p Point to translate * @return the translated point name * @throws java.lang.Exception */ static public String Translation(String name, String a, String b, String p) throws Exception { synchronized (getC()) { if (p.equals("undefined")) { p=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); p=parseVariables(p); if (name.equals("")) { c("@builtin@/trans("+a+","+b+","+p+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/trans("+a+","+b+","+p+")"); } return LastNObjectsName(1); } } /** * Reflect the point b with center a * @param name Name of the Reflect point * @param a Symmetry center * @param b Point to reflect * @return the symmetric point name */ static public String Symmetry(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Point"); if (name.equals("")) { c(sn+"(2*x("+a+")-x("+b+"),2*y("+a+")-y("+b+"))"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"(2*x("+a+")-x("+b+"),2*y("+a+")-y("+b+"))"); } return LastNObjectsName(1); } } static public String SymétrieCentrale(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Point"); if (name.equals("")) { c(sn+"(2*x("+a+")-x("+b+"),2*y("+a+")-y("+b+"))"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"(2*x("+a+")-x("+b+"),2*y("+a+")-y("+b+"))"); } return LastNObjectsName(1); } } /** * Creates the perpendicular bisector between two points a and b * @param name Name of the perpendicular bisector * @param a first point * @param b second point * @return the perpendicular bisector name */ static public String PerpendicularBisector(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); if (name.equals("")) { c("@builtin@/med("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/med("+a+","+b+")"); } return LastNObjectsName(1); } } static public String Médiatrice(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); if (name.equals("")) { c("@builtin@/med("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/med("+a+","+b+")"); } return LastNObjectsName(1); } } /** * Create the angle bisector between 3 points a, b and c * @param name Name of the perpendicular bisector * @param a first point * @param b second point * @param c third point * @return the angle bisector name * @throws java.lang.Exception */ static public String AngleBisector(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); if (name.equals("")) { c("@builtin@/biss("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/biss("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } static public String Bissectrice(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); if (name.equals("")) { c("@builtin@/biss("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/biss("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } /** * Create the circumcicular circle between 3 points a, b and c * @param name Name of the perpendicular bisector * @param a first point * @param b second point * @param c third point * @return the circumcicular circle name * @throws java.lang.Exception */ static public String Circle3pts(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); if (name.equals("")) { c("@builtin@/circ("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/circ("+a+","+b+","+c+")"); } getC().lastButN(0).setDefaults(); return LastNObjectsName(1); } } static public String Cercle3pts(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); if (name.equals("")) { c("@builtin@/circ("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/circ("+a+","+b+","+c+")"); } getC().lastButN(0).setDefaults(); return LastNObjectsName(1); } } /** * Creates the circle around a with radius bc * @param name Name of the circle * @param a center point * @param b first point * @param c second point * @return the circle name * @throws java.lang.Exception */ static public String Circle3(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); String sn = Global.name("name.short.Circle3"); if (name.equals("")) { c(sn+"("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } static public String Cercle3(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); String sn = Global.name("name.short.Circle3"); if (name.equals("")) { c(sn+"("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } /** * Create the circumcircular arc between 3 points a, b and c * @param name Name of the perpendicular bisector * @param a first point * @param b second point * @param c third point * @return the circumcircular arc name * @throws java.lang.Exception */ static public String Arc3pts(String name, String a, String b, String c) throws Exception { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); if (name.equals("")) { c("@builtin@/arc("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"=@builtin@/arc("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } /** * Creates the intersection between two objects. If you provide a name * for the intersection, only one intersection point will be created. * If you give the empty string "" as name parameter, two intersection * points will be created, if the a and b objects are two circles * or line/circle. * @param name Name of the intersection point * @param a Name of first object * @param b Name of second object * @param order Number which gives the order of intersection : 0 means first * @return Name of intersection point * @throws java.lang.Exception * @see #Intersection2 */ static public String OrderedIntersection(String name, String a, String b, String order) throws Exception { synchronized (getC()) { if (order.equals("undefined")) { order=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); order=parseVariables(order); String sn = Global.name("name.short.Intersection"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } IntersectionObject i=(IntersectionObject) getC().lastButN(0); i.setFirst(Integer.valueOf(order)==0); return LastNObjectsName(1); } } static public String IntersectionOrdonnée(String name, String a, String b, String order) throws Exception { synchronized (getC()) { if (order.equals("undefined")) { order=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); order=parseVariables(order); String sn = Global.name("name.short.Intersection"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } IntersectionObject i=(IntersectionObject) getC().lastButN(0); i.setFirst(Integer.valueOf(order)==0); return LastNObjectsName(1); } } /** * Creates the intersection between two objects. If you provide a name * for the intersection, only one intersection point will be created. * If you give the empty string "" as name parameter, two intersection * points will be created, if the a and b objects are two circles * or line/circle. * @param name Name of the intersection point * @param a Name of first object * @param b Name of second object * @return Name of intersection point * @throws java.lang.Exception * @see #Intersection2 */ static public String Intersection(String name, String a, String b) throws Exception { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Intersection"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } return LastNObjectsName(1); } } /** * When two objects have two intersection points (two circles or one line/one circle) * you may use this command to create them both. * @param name1 Name of first intersection point * @param name2 Name of second intersection point * @param a Name of first object * @param b Name of second object * @return Name of intersection point * @see #Intersection */ static public String Intersection2(String name1, String name2, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name2; name2=name1; name1=""; if (b.equals("undefined")) { b=a; a=name2; name2=""; } } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Intersection"); if (name1.equals("")) { c("I2,I1="+sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { c(name2+","+name1+"="+sn+"("+a+","+b+")"); } return LastNObjectsName(2); } } /** * General case: The number of the intersection points depends * on the nature of the lines intersected * @param name of the first intersection point * @param a Name of first object * @param b Name of second object * @return list of the intersection points in a String * @throws java.lang.Exception * @see #Intersection */ static public String Intersections(String name, String a, String b) throws Exception { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Intersection"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } if (getC().find(a) instanceof PrimitiveLineObject&&getC().find(b) instanceof PrimitiveLineObject) { return LastNObjectsName(1); } else { if ((getC().find(a) instanceof PrimitiveCircleObject||getC().find(b) instanceof PrimitiveCircleObject) ||(getC().find(a) instanceof PrimitiveLineObject&&getC().find(b) instanceof QuadricObject) ||(getC().find(a) instanceof QuadricObject&&getC().find(b) instanceof PrimitiveLineObject)) { return LastNObjectsName(2); } else { if (getC().find(a) instanceof QuadricObject&&getC().find(b) instanceof QuadricObject) { return LastNObjectsName(4); } else { if (getC().find(a) instanceof FunctionObject||getC().find(b) instanceof FunctionObject) { return LastNObjectsName(1); } else { throw new Exception(Loc("notgoodtype")); } } } } } } /** * Creates a line between two points * @param name Name of the line (suggestion) * @param a Name of first point * @param b Name of second point * @return Name of the created line */ static public String Line(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Line"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } NormalizeLast(); return LastNObjectsName(1); } } static public String Droite(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Line"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } NormalizeLast(); return LastNObjectsName(1); } } /** * Creates a ray from point a to point b * @param name Name of the ray (suggestion) * @param a Name of first point * @param b Name of second point * @return Name of the created ray */ static public String Ray(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Ray"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } NormalizeLast(); return LastNObjectsName(1); } } static public String DemiDroite(String name, String a, String b) { synchronized (getC()) { if (b.equals("undefined")) { b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Ray"); if (name.equals("")) { c(sn+"("+a+","+b+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+")"); } NormalizeLast(); return LastNObjectsName(1); } } /** * Creates an angle defined by 3 points a,b and c (b is the vertex). * @param name Name of the angle (suggestion) * @param a Name of first point * @param b Name of the vertex * @param c Name of the third point * @return Name of the created angle */ static public String Angle(String name, String a, String b, String c) { synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); c=parseVariables(c); String sn = Global.name("name.short.Angle"); if (name.equals("")) { c(sn+"("+a+","+b+","+c+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+","+c+")"); } return LastNObjectsName(1); } } /** * Creates an angle defined by 2 points a,b and an expression c (b is the vertex). * @param name Name of the angle (suggestion) * @param a Name of first point * @param b Name of the vertex * @param c angle in degree * @return Name of the created angle */ static public String FixedAngle(String name, String a, String b, String c) throws Exception{ synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Angle"); try { if (name.equals("")) { c(sn+"("+a+","+b+","+Math.round(Double.valueOf(c)*1E13)/1E13+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+","+Math.round(Double.valueOf(c)*1E13)/1E13+")"); } NormalizeLast(); getC().lastButN(0).setDefaults(); return LastNObjectsName(1); } catch (NumberFormatException e) { try { if (name.equals("")) { c(sn+"("+a+","+b+",0)"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+",0)"); } NormalizeLast(); getC().lastButN(0).setDefaults(); c=parseVariables(c); ((FixedAngleObject) getC().lastButN(0)).setFixed(c); return LastNObjectsName(1); } catch (Exception ex) { throw new Exception(Loc("notgoodtype")); } } } } static public String AngleFixe(String name, String a, String b, String c) throws Exception{ synchronized (getC()) { if (c.equals("undefined")) { c=b; b=a; a=name; name=""; } a=parseVariables(a); b=parseVariables(b); String sn = Global.name("name.short.Angle"); try { if (name.equals("")) { c(sn+"("+a+","+b+","+Math.round(Double.valueOf(c)*1E13)/1E13+")"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+","+Math.round(Double.valueOf(c)*1E13)/1E13+")"); } NormalizeLast(); getC().lastButN(0).setDefaults(); return LastNObjectsName(1); } catch (NumberFormatException e) { try { if (name.equals("")) { c(sn+"("+a+","+b+",0)"); getC().lastButN(0).setShowName(false); } else { name=parseVariables(name); c(name+"="+sn+"("+a+","+b+",0)"); } NormalizeLast(); getC().lastButN(0).setDefaults(); c=parseVariables(c); ((FixedAngleObject) getC().lastButN(0)).setFixed(c); return LastNObjectsName(1); } catch (Exception ex) { throw new Exception(Loc("notgoodtype")); } } } } /** * Set angles as reflex or not. *
Example : ReflexAngle("a1,a2",true) * @param name Name(s) of object. * @param bool "true" to set as reflex, "false" to have only angles less than 180°. * @throws java.lang.Exception */ static public void ReflexAngle(String name, boolean bool) throws Exception { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (!(o instanceof AngleObject)) { throw new Exception(Loc("notgoodtype")); } if (o!=null && true) { o.setObtuse(bool); } } } static public void AngleRentrant(String name, boolean bool) throws Exception { String[] names=parseVariables(name).split(","); for (String name1 : names) { ConstructionObject o = getC().find(name1); if (!(o instanceof AngleObject)) { throw new Exception(Loc("notgoodtype")); } if (o!=null && true) { o.setObtuse(bool); } } } /** * Execute a macro-construction m with parameters params * @param lastObjName Name of last created object(s) * @param macroname Name of macro * @param params list of objects (e.g. "A,E,F,G") * @return Name of the last created object or the String array with all targets name */ static public Object ExecuteMacro(String lastObjName, String macroname, String params) { synchronized (getC()) { if (params.equals("undefined")) { params=macroname; macroname=lastObjName; lastObjName=""; } if (lastObjName.equals("")) { c(macroname+"("+parseVariables(params)+")"); //getC().lastButN(0).setShowName(false); } else { c(parseVariables(lastObjName)+"="+macroname+"("+parseVariables(params)+")"); } String[] TargetsNamesArray = MacroRunner.TargetsNameList.toArray(new String[MacroRunner.TargetsNameList.size()]); for (int i=0; i