[2471] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <iostream>
|
---|
| 5 | #include <math.h>
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | #include <vector>
|
---|
| 9 | #include <string>
|
---|
| 10 |
|
---|
| 11 | #include "piacmd.h"
|
---|
| 12 | #include "timing.h"
|
---|
| 13 | #include "srandgen.h"
|
---|
| 14 | #include "nobjmgr.h"
|
---|
| 15 | #include "pistdimgapp.h"
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | // Exemple de module chargeable ds piapp
|
---|
| 19 |
|
---|
| 20 | // Classe Drawer de Test
|
---|
| 21 | class TstSpeedDrw : public PIDrawer {
|
---|
| 22 | public:
|
---|
| 23 | TstSpeedDrw(int npt, int nblk);
|
---|
| 24 | virtual ~TstSpeedDrw();
|
---|
| 25 |
|
---|
| 26 | virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
|
---|
| 27 | virtual void UpdateLimits();
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | protected:
|
---|
| 31 | int _npt, _nblk;
|
---|
| 32 | double * _mesx;
|
---|
| 33 | double * _mesy;
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | /* --Methode-- */
|
---|
| 37 | TstSpeedDrw::TstSpeedDrw(int npt, int nblk)
|
---|
| 38 | : PIDrawer()
|
---|
| 39 | {
|
---|
| 40 | if (nblk > 1) {
|
---|
| 41 | int q = npt / nblk; npt = q*nblk;
|
---|
| 42 | }
|
---|
| 43 | _npt = npt; _nblk = nblk;
|
---|
| 44 | _mesx = new double[npt];
|
---|
| 45 | _mesy = new double[npt];
|
---|
| 46 | double dx = 3./npt;
|
---|
| 47 | for(int i=0; i<npt; i++) {
|
---|
| 48 | double x = i*dx;
|
---|
| 49 | _mesx[i] = x;
|
---|
[2500] | 50 | _mesy[i] = x*x + 3*drandpm1();
|
---|
[2471] | 51 | }
|
---|
| 52 | mName = "TstSpeedDrw";
|
---|
| 53 | cout << " TstSpeedDrw::TstSpeedDrw(" << npt << "," << nblk << ")" << endl;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | /* --Methode-- */
|
---|
| 57 | TstSpeedDrw::~TstSpeedDrw()
|
---|
| 58 | {
|
---|
| 59 | delete[] _mesx;
|
---|
| 60 | delete[] _mesy;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /* --Methode-- */
|
---|
| 64 | void TstSpeedDrw::UpdateLimits()
|
---|
| 65 | {
|
---|
| 66 | double xmin = -0.1 ;
|
---|
| 67 | double xmax = 3.1;
|
---|
[2500] | 68 | double ymin = -2.;
|
---|
| 69 | double ymax = 11.;
|
---|
[2471] | 70 | PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
|
---|
| 71 | PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax);
|
---|
| 72 | SetLimits(xmin,xmax,ymin,ymax);
|
---|
| 73 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | /* --Methode-- */
|
---|
| 78 | void TstSpeedDrw::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
| 79 | {
|
---|
| 80 | /*
|
---|
| 81 | PIMarker mrk = GetGraphicAtt().GetMarker();
|
---|
| 82 | mrk = (mrk != PI_NotDefMarker) ? mrk : PI_DotMarker;
|
---|
| 83 | int msz = GetGraphicAtt().GetMarkerSz();
|
---|
| 84 | if (msz < 1) msz = 1;
|
---|
| 85 | g->SelMarker(msz, mrk);
|
---|
| 86 | */
|
---|
| 87 | PrtTim("TstSpeedDrw::Draw() START");
|
---|
| 88 | if (_nblk < 2) {
|
---|
| 89 | for(int i=0; i<_npt; i++)
|
---|
| 90 | g->DrawMarker(_mesx[i], _mesy[i]);
|
---|
| 91 | PrtTim("TstSpeedDrw::Draw() Blk=1 done");
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | int q = _npt/_nblk;
|
---|
| 95 | PIGrCoord* grx = new PIGrCoord[_nblk];
|
---|
| 96 | PIGrCoord* gry = new PIGrCoord[_nblk];
|
---|
| 97 | for(int k=0; k<q; k++) {
|
---|
| 98 | int off = k*_nblk;
|
---|
| 99 | for(int j=0; j<_nblk; j++) {
|
---|
| 100 | grx[j] = _mesx[off+j];
|
---|
| 101 | gry[j] = _mesy[off+j];
|
---|
| 102 | }
|
---|
| 103 | g->DrawMarkers(grx, gry, _nblk);
|
---|
| 104 | }
|
---|
| 105 | PrtTim("TstSpeedDrw::Draw() Blk>1 done");
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | // Declaration de la fonction d'activation et de desactivation du module
|
---|
| 111 | extern "C" {
|
---|
| 112 | void exmoddrw_init();
|
---|
| 113 | void exmoddrw_end();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | // Une classe commande-executor, permettant d'enregistrer de
|
---|
| 118 | // nouvelles commandes a piapp
|
---|
| 119 | class exmoddrwExecutor : public CmdExecutor {
|
---|
| 120 | public:
|
---|
| 121 | exmoddrwExecutor();
|
---|
| 122 | virtual ~exmoddrwExecutor();
|
---|
| 123 | // Execute s'occupe de l'execution effective des commandes
|
---|
| 124 | virtual int Execute(string& keyw, vector<string>& args, string& toks);
|
---|
| 125 | };
|
---|
| 126 |
|
---|
| 127 | /* --Methode-- */
|
---|
| 128 | exmoddrwExecutor::exmoddrwExecutor()
|
---|
| 129 | {
|
---|
| 130 |
|
---|
| 131 | PIACmd * mpiac;
|
---|
| 132 | NamedObjMgr omg;
|
---|
| 133 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
| 134 |
|
---|
| 135 | // On enregistre deux nouvelles commandes
|
---|
| 136 | string hgrp = "ExModDrw";
|
---|
| 137 | // commande excmd1
|
---|
| 138 | string kw = "tspeeddrw";
|
---|
| 139 | string usage = "tspeeddrw npt nblk gr_opt \n" ;
|
---|
| 140 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /* --Methode-- */
|
---|
| 144 | exmoddrwExecutor::~exmoddrwExecutor()
|
---|
| 145 | {
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /* --Methode-- */
|
---|
| 149 | int exmoddrwExecutor::Execute(string& kw, vector<string>& tokens, string&)
|
---|
| 150 | {
|
---|
| 151 |
|
---|
| 152 | NamedObjMgr omg;
|
---|
| 153 | if (kw == "tspeeddrw") {
|
---|
| 154 | if (tokens.size() < 2) {
|
---|
| 155 | cout << "Usage: tspeeddrw npt nblk gr_opt" << endl;
|
---|
| 156 | return(0);
|
---|
| 157 | }
|
---|
| 158 | int npt = atoi(tokens[0].c_str());
|
---|
| 159 | int nblk = atoi(tokens[1].c_str());
|
---|
| 160 | string opt = "";
|
---|
| 161 | if (tokens.size() > 2) opt = tokens[2];
|
---|
| 162 | TstSpeedDrw* drw = new TstSpeedDrw(npt, nblk);
|
---|
| 163 | string name = "TstSpeedDrw";
|
---|
| 164 | omg.GetImgApp()->DispScDrawer(drw, name, opt);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | return(0);
|
---|
| 168 |
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | static exmoddrwExecutor * tdrwex = NULL;
|
---|
| 172 | /* Nouvelle-Fonction */
|
---|
| 173 | void exmoddrw_init()
|
---|
| 174 | {
|
---|
| 175 | // Fonction d'initialisation du module
|
---|
| 176 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
| 177 | if (tdrwex) delete tdrwex;
|
---|
| 178 | tdrwex = new exmoddrwExecutor;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | /* Nouvelle-Fonction */
|
---|
| 182 | void exmoddrw_end()
|
---|
| 183 | {
|
---|
| 184 | // Desactivation du module
|
---|
| 185 | if (tdrwex) delete tdrwex;
|
---|
| 186 | tdrwex = NULL;
|
---|
| 187 | }
|
---|
| 188 |
|
---|