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