Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Demo.cxx

Go to the documentation of this file.
00001 // 
00002 #include "Demo.h"
00003 
00004 // gui event graphics include files
00005 #include "gui/GuiMgr.h"
00006 #include "gui/DisplayControl.h"
00007 #include <strstream>
00008 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00009 // A class with 3-d info. It will be represented by a cube beween (a,a,a) and (b,b,b),
00010 // and has a name that should plotted in the middle. 
00011 class SimpleBox 
00012 {
00013 public:
00014     SimpleBox(double a, double b, const std::string& name)
00015         :m_a(a), m_b(b), m_name(name){}
00016     ~SimpleBox(){}
00017     double a()const{return m_a;}
00018     double b()const{return m_b;}
00019     const std::string& name()const{return m_name;}
00020 private:
00021     double m_a, m_b;
00022     std::string m_name;
00023 };
00024 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00025 // The class that makes a representation for plotting. It must implement
00026 // an update() method to create the representation
00027 class SimpleBoxRep : public gui::DisplayRep
00028 {
00029 public:
00030     SimpleBoxRep(const SimpleBox* pbox):m_pbox(pbox)
00031     {
00032        // update(); // make rep in constructor
00033     }
00034     void update()
00035     {
00036         using namespace gui;
00037         if( hasRepresentation() ) return;
00038         set_color("blue");
00039         double a = m_pbox->a(), b = m_pbox->b();
00040 
00041         // create a list of the vertices of the box
00042         addVertex(GraphicsVector( a, a, a));
00043         addVertex(GraphicsVector( a, b, a));
00044         addVertex(GraphicsVector( b, b, a));
00045         addVertex(GraphicsVector( b, a, a));
00046         addVertex(GraphicsVector( a, a, b));
00047         addVertex(GraphicsVector( a, b, b));
00048         addVertex(GraphicsVector( b, b, b));
00049         addVertex(GraphicsVector( b, a, b));
00050  
00051         // and a list of lines to draw
00052         static int q[]={0,1,2,3,0,4,5,6,7,4,-1, 1,5,-1,2,6,-1,3,7,-1};
00053         indexedLineSet(q,sizeof(q)/sizeof(int));
00054  
00055         // go to the center and draw the label
00056         double c = 0.5*(a+b); move_to(GraphicsVector(c,c,c));
00057         drawText(m_pbox->name());
00058         set_color("black");
00059     }
00060 private:
00061     const SimpleBox* m_pbox;
00062 };
00063 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00064 // implementation of the Demo class
00065 
00066 Demo::Demo(gui::DisplayControl & display) : _number(0)
00067 , _box1(new SimpleBox(-400,400, "1"))
00068 , _box2(new SimpleBox(-300,-200, "2"))
00069 , _box3(new SimpleBox(-200,-100, "3"))
00070 , _box4(new SimpleBox(-100, 100, "4"))
00071 {
00072     using namespace gui;
00073     
00074     // create and add their reps to the display, some with buttons in the Display menu
00075     // to control their visibility
00076     
00077     
00078     DisplayRep* r1 =  new SimpleBoxRep(_box1);
00079     DisplayRep* r11 = new SimpleBoxRep(_box2);
00080     DisplayRep* r12 = new SimpleBoxRep(_box3);
00081     
00082     DisplayControl::DisplaySubMenu& sm1 = display.subMenu("Boxes..", r1);
00083     DisplayControl::DisplaySubMenu& sm2 = sm1.subMenu("box 2", r11);
00084     sm1.add(r12, "box3");
00085     sm2.add(new SimpleBoxRep(_box4), "box4");
00086     
00087     
00088 }
00089 
00090 void Demo::process()
00091 {
00092     // change something that will show up in the display
00093     ++_number;
00094 }
00095 
00096 Demo::~Demo() 
00097 {
00098     delete _box1;
00099     delete _box2;
00100     delete _box3;
00101     delete _box4;
00102 }
00103 

Generated at Mon Nov 26 18:18:10 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000