source: Sophya/trunk/SophyaPI/DemoPIApp/exmoddrw.cc@ 2471

Last change on this file since 2471 was 2471, checked in by ansari, 22 years ago

Ajout module chargeable exemple / vitesse de trace . Reza 4 Dec 2003

  • Property svn:executable set to *
File size: 4.1 KB
Line 
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
21class TstSpeedDrw : public PIDrawer {
22public:
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
30protected:
31 int _npt, _nblk;
32 double * _mesx;
33 double * _mesy;
34};
35
36/* --Methode-- */
37TstSpeedDrw::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;
50 _mesy[i] = x*x + drandpm1();
51 }
52 mName = "TstSpeedDrw";
53 cout << " TstSpeedDrw::TstSpeedDrw(" << npt << "," << nblk << ")" << endl;
54}
55
56/* --Methode-- */
57TstSpeedDrw::~TstSpeedDrw()
58{
59 delete[] _mesx;
60 delete[] _mesy;
61}
62
63/* --Methode-- */
64void TstSpeedDrw::UpdateLimits()
65{
66 double xmin = -0.1 ;
67 double xmax = 3.1;
68 double ymin = -1.;
69 double ymax = 10.;
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-- */
78void 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
111extern "C" {
112void exmoddrw_init();
113void exmoddrw_end();
114}
115
116
117// Une classe commande-executor, permettant d'enregistrer de
118// nouvelles commandes a piapp
119class exmoddrwExecutor : public CmdExecutor {
120public:
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-- */
128exmoddrwExecutor::exmoddrwExecutor()
129{
130
131PIACmd * mpiac;
132NamedObjMgr omg;
133mpiac = omg.GetImgApp()->CmdInterpreter();
134
135// On enregistre deux nouvelles commandes
136string hgrp = "ExModDrw";
137// commande excmd1
138string kw = "tspeeddrw";
139string usage = "tspeeddrw npt nblk gr_opt \n" ;
140mpiac->RegisterCommand(kw, usage, this, hgrp);
141}
142
143/* --Methode-- */
144exmoddrwExecutor::~exmoddrwExecutor()
145{
146}
147
148/* --Methode-- */
149int exmoddrwExecutor::Execute(string& kw, vector<string>& tokens, string&)
150{
151
152NamedObjMgr omg;
153if (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
167return(0);
168
169}
170
171static exmoddrwExecutor * tdrwex = NULL;
172/* Nouvelle-Fonction */
173void exmoddrw_init()
174{
175// Fonction d'initialisation du module
176// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
177if (tdrwex) delete tdrwex;
178tdrwex = new exmoddrwExecutor;
179}
180
181/* Nouvelle-Fonction */
182void exmoddrw_end()
183{
184// Desactivation du module
185if (tdrwex) delete tdrwex;
186tdrwex = NULL;
187}
188
Note: See TracBrowser for help on using the repository browser.