Copyright Hilaire Fernandes 1999
hilaire.fernandes@iname.com
Version 0.1


1. How to build a new class object ?






1. How to build a new class object ?

I will work with an example : a point define by a circle and its curvilign abscissa

a. build a new class :

. first determine the object type :
 it can be FIG_POINT, FIG_DROITE, etc. This is a generic type. It means FIG_POINT represents different kind of point (free, on a line, etc). This leads us to :
. the classe type : let says POINT_CE_CU for a point on a circle and positionned with its curvilign abscissa, define it.
. next what kind of parent : two pointers on cercle_c and valeur_c generic class
So the new class could look like :

class point_sur_cercle_curviligne:public point_c {
// we get all the methods from point_c as drawing and mouse intersection method
 public:
// all stuff public, some people think it's evil ;) , what do you think ?
  valeur_c *abscissa;
  cercle_c *circle;
 point_sur_cercle_curviligne (void):point_c () {
// we need this empty methods when we load a geo file
  classe = POINT_CE_CU;
// the type is set when the point_c constructor is called
}
 point_sur_cercle_curviligne (double x, double y, liste_elem & lp):point_c ()
{
figure_c *parent1, *parent2;

classe = POINT_CE_CU;
parent1 = (figure_c *) lp.lire (1);
parent2 = (figure_c *) lp.lire (2);
if (parent1->type == FIG_CERCLE) {
 circle = (cercle_c *) parent1;
 abscissa = (valeur_c *) parent2;
}
else {
 circle = (cercle_c *) parent2;
 abscissa = (valeur_c *) parent1;
}

/* next compute the coordinate of our new point */
 actualise ();
 init_nom ();
}

// define the needed methods, in this exemple you can look at the point_sur_cercle , the methods will be quite close
  void move (int mx, int my);
  // move by vector (mx,my)
  void actualise ();
  // recompute point position
  void sauve_disk (FILE * f);
  // save its onwn data to f
  void lire_disk (FILE * f);
  char dependance (figure_c * fig);
  // check if the fig object is a parent of this object
}

Write the methode in geoclass.cc (subject to change for the location, choose the apropriate file)

b. says to the construction method we have a new class object :

. in file mode_obj.h : 
   .look for class creer_point_repere_c:... how we create a new kind of point object given its abscissa, this tells us thereis 1 mode (#define NB_MOD 1), increment this to 2.
   . next in method reset, we saw mode16 and cas_possible16 variable
   . at the begining of the fill search for cas_possibe16, and put cas_possibe16[2]
. in file var_decl.h :
   . seek for mode16 and add :
           {FIG_CERCLE, FIG_VALEUR, NO_OBJECT}},
   . in cas_possible16 declaration change 1 to 2 and add one 1 in the assignement

c. add the construction call

. in file main.cc :
   . search for point_repere method
   . in the switch-case block add a case 1:  block with the apropriate calls
       

d. says to the load & macro procedure there is a new kind of object 

. in file traite.cc :
   . in lire_figure & creer_objet methods add the apropriate case POINT_CI_CU


That's it!




