Logo Search packages:      
Sourcecode: wims version File versions

void rene::zirkel::ZirkelCanvas::defineMacro ( Construction  c,
Macro  m,
boolean  targetsonly,
boolean  superhide,
String  prompt[],
boolean  hideduplicates 
) throws ConstructionException [inline]

Define a macro based on a construction in c and the targets and parameters in this construction. Store the macro in m.

Parameters:
 

Definition at line 2936 of file ZirkelCanvas.java.

References rene::zirkel::construction::Construction::add(), canConvert(), rene::zirkel::construction::Construction::clearConstructables(), rene::zirkel::construction::Construction::clearErrors(), rene::zirkel::construction::Construction::clearTranslations(), rene::zirkel::construction::Construction::clearTranslators(), rene::zirkel::construction::Construction::determineConstructables(), rene::zirkel::construction::Construction::elements(), rene::zirkel::construction::Construction::find(), rene::zirkel::construction::Construction::getErrors(), rene::zirkel::construction::Construction::getParameters(), rene::zirkel::construction::Construction::getTargets(), rene::zirkel::construction::Construction::getX(), rene::zirkel::macro::Macro::hideDuplicates(), needed(), rene::zirkel::construction::Construction::runTranslators(), rene::zirkel::objects::UserFunctionObject::setExpressions(), rene::zirkel::objects::FunctionObject::setExpressions(), rene::zirkel::construction::Construction::setParameterAsConstructables(), rene::zirkel::macro::Macro::setParams(), rene::zirkel::macro::Macro::setPromptFor(), rene::zirkel::macro::Macro::setPromptName(), rene::zirkel::objects::FunctionObject::setRange(), and rene::zirkel::construction::Construction::setTranslation().

      {     Vector P=c.getParameters(),T=c.getTargets();
            c.setTranslation(m); // for construction expressions only (windoww etc.)
            c.clearTranslations();
            if (T.size()==0) // got no targets 
                  c.determineConstructables();
            else // got targets
            {     c.clearConstructables();
                  c.setParameterAsConstructables();
                  for (int i=0; i<T.size(); i++)
                  {     c.determineConstructables((ConstructionObject)T.elementAt(i));
                  }
            }
            // Make sure the counter for the macro object names starts
            // fresh (P1, P2, ...)
            Count.setAllAlternate(true);
            // Walk through the construction and copy all marked objects
            // to the macro definition.
            m.clearTranslators();
            Enumeration e=c.elements();
            while (e.hasMoreElements())
            {     ConstructionObject o=(ConstructionObject)e.nextElement();
                  if (o instanceof TwoPointLineObject && 
                        canConvert(c,(TwoPointLineObject)o) && o.isMainParameter())
                  {     ((TwoPointLineObject)o).getP1().setFlag(false);
                        ((TwoPointLineObject)o).getP2().setFlag(false);
                  }                             
            }
            e=c.elements();
            while (e.hasMoreElements())
            {     ConstructionObject oc,o=(ConstructionObject)e.nextElement();
                  if (o.isFlag() &&
                        !(o.isParameter() && !o.isMainParameter() && !needed(c,o,null)))
                  {     // System.out.println(o.getName()+", parameter: "+o.isParameter()+
                        //    ", main: "+o.isMainParameter()+", needed "+needed(c,o,null));
                        // Now copy to the macro, but make sure that parameters
                        // are simplified to their object type. E.g., an
                        // objectpoint becomes a point, if it is a parameter.
                        if (o instanceof PointObject && o.isParameter())
                        {     PointObject p=(PointObject)o;
                              if (p.isSpecialParameter() && p.dependsOnParametersOnly())
                                    oc=(ConstructionObject)p.copy();
                              else
                                    oc=new PointObject(c,p.getX(),p.getY());
                        }
                        else if (o instanceof FunctionObject && o.isParameter())
                        {     FunctionObject fo=new FunctionObject(c);
                              fo.setExpressions("x","0","0");
                              fo.setRange("-10","10","0.1");
                              oc=fo;
                        }
                        else if (o instanceof UserFunctionObject && o.isParameter())
                        {     UserFunctionObject fo=new UserFunctionObject(c);
                              fo.setExpressions("x","0");
                              oc=fo;
                        }
                        else if (o instanceof ExpressionObject && o.isParameter())
                        {     oc=new ExpressionObject(c,0,0);
                              ((ExpressionObject)oc).setExpression(o.getValue()+"",
                                          o.getConstruction());
                              ((ExpressionObject)oc).setCurrentValue(o.getValue());
                        }
                        else if (o instanceof TwoPointLineObject && 
                              canConvert(c,(TwoPointLineObject)o) && o.isParameter())
                        {     oc=new PrimitiveLineObject(c);
                        }                             
                        else if (o instanceof PrimitiveLineObject && 
                              !(o instanceof TwoPointLineObject) &&
                              !(o instanceof FixedAngleObject) &&
                              o.isParameter())
                        {     oc=new PrimitiveLineObject(c);
                        }
                        else if (o instanceof PrimitiveCircleObject && o.isParameter())
                        {     oc=new PrimitiveCircleObject(c,
                                    ((PrimitiveCircleObject)o).getP1());
                              oc.translateConditionals();
                              oc.translate();
                        }
                        else if (o instanceof AreaObject && o.isParameter())
                        {     oc=new AreaObject(c,new Vector());
                              oc.translateConditionals();
                              oc.translate();
                        }
                        else
                        {     oc=(ConstructionObject)o.copy();
                        }
                        if (oc!=null)
                        {     m.add(oc);
                              if (o.isMainParameter()) oc.setName(o.getName());
                              if (targetsonly && !o.isTarget() && !o.isParameter())
                              {     if (superhide) oc.setSuperHidden(true);
                                    else oc.setHidden(true);
                              }
                              if (o.isParameter() && o.isHidden())
                              {     oc.setHidden(true);
                              }
                              // All parameters in the constructions translate to
                              // the paramters in the macro definition.
                              o.setTranslation(oc);
                        }
                  }
                  else o.setTranslation(null);
            }
            e=c.elements();
            while (e.hasMoreElements())
            {     ConstructionObject o=(ConstructionObject)e.nextElement();
                  if (o.isFlag() && !o.isParameter())
                        o.laterTranslate(c);
            }
            Count.setAllAlternate(false);
            // translate the @... forward declarations in FindObjectExpression.
            c.clearErrors();
            m.runTranslators(c);
            // see if any errors occured (@.. to nonexisting object, generated
            // by the FindObjectExpression on translation.
            e=c.getErrors();
            if (e.hasMoreElements())
            {     warning((String)e.nextElement(),"macroerror");
            }
            // Now set the paramter array and make sure it is translated
            // to the objects in the macro definition.
            ConstructionObject Params[]=new ConstructionObject[P.size()];
            for (int i=0; i<P.size(); i++)
            {     Params[i]=((ConstructionObject)P.elementAt(i)).getTranslation();
            }
            m.setParams(Params);
            String p[]=new String[prompt.length];
            for (int j=0; j<prompt.length; j++)
            {     ConstructionObject o=c.find(prompt[j]);
                  if (o==null || o.getTranslation()==null ||
                        !(o instanceof FixedCircleObject || 
                              o instanceof FixedAngleObject ||
                              o instanceof ExpressionObject))
                        throw new ConstructionException(
                              Zirkel.name("exception.prompt"));
                  for (int i=0; i<P.size(); i++)
                  {     ConstructionObject op=(ConstructionObject)P.elementAt(i);
                        if (op==o)
                              throw new ConstructionException(
                                    Zirkel.name("exception.prompt.parameter"));
                  }
                  p[j]=o.getTranslation().getName();
            }
            m.setPromptFor(p);
            for (int i=0; i<prompt.length; i++)
                  m.setPromptName(i,prompt[i]);
            m.hideDuplicates(hideduplicates);
      }


Generated by  Doxygen 1.6.0   Back to index