Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

Getting started

OGraphic objects use
This library is based on a generic (and abstract) OGraphic object use. From this object, the GOMLib can be easily extended with new object types (see section Extend the library). The GOMLib proposes too implementations of standard graphics objects (OPoint, OLine, OArc, OCurve, and so on). The following function gives an example of objects create and delete:
    void init1()
    {
            OGraphic *o1,*o2;
            o1 = new OPoint(1,1);
            o1->print();
            o2 = new OLine(1,1,8,8);
            o2->print();
            o1->~OGraphic();
            o2->~OGraphic();
    }       //de
The GOMLib is based on polymorphism, so only OGraphic* are used for objects manipulation. You can use the OGraphic::clone() function in order to copy your objects.

    void copy()
    {
            OGraphic *o1 = new OPoint(1,2);
            o1->print();
            OGraphic *o2 = o1->clone();
            o1->~OGraphic(); //
            o2->print();
            o2->~OGraphic();
    }       //de
However, you can use the standard object types in your programs.

    void init2()
    {
            OPoint *o1 = new OPoint(5,1);
            cout << o1->getX() << endl;
            OLine *o2 = new OLine(1,1,8,8);
            cout << o2->getLength() << endl;
            o1->~OPoint();
            o2->~OLine();
    }       //de
You can use too directly the standard objects. However, this using create automatic memory allocation, and can generate some errors with the use of container objects (see section Container objects).

    void init3()
    {
            OPoint o1(5,1);
            cout << o1.getX() << endl;
            OLine o2(1,1,8,8);
            cout << o2.getLength() << endl;
    }       //de
Read/Write of graphical objects
The GOMLib represents the graphical knowledge through the Graphics Object Modelling Language "GOML". The GOML files are extended with ".gom". Use the different "gom" functions gomRead() and gomWrite() to read/write the "gom" files. You can export too in XML and SVG formats with the functions xmlWrite() and svgWrite(). The following function gives a simple example of arc write and read:
    void rw()
    {
            OGraphic* p;
            OPoint ptb(50,50),ptc(100,50),pte(100,100);
            p = new OArc(ptb,ptc,pte,false);
            gomWrite(p,"es.gom");
            xmlWrite(p,"es.xml");
            svgWrite(p,"es.svg");
            p->~OGraphic();
            p = gomRead("es.gom");
            p->print();
    }       //de
The read function imports a OGraphic*, in order to access standard objects' functions, you must:

Use the OGraphic::getName() function and the object dynamic cast functionnality of "GOMLib\POUtility.hpp". The following function gives an example of type test and dynamic cast use.

    void dynamic()
    {
            OGraphic* p;
            OPoint ptb(50,50),ptc(100,50),pte(100,100);
            p = new OArc(ptb,ptc,pte,false);
            gomWrite(p,"es.gom");   
            p->~OGraphic();
            p = gomRead("es.gom");
            if(p->getName()=="OArc")
                    {
                    OArc *a = castOArc(p);
                    cout << a->getRadius() << endl;
                    a->~OArc();
                    }
            else
                    p->~OGraphic();
    }       //de

Generated on Fri Jul 30 19:21:03 2004 for GOMLib by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001