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

Last change on this file since 4033 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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