source: Sophya/trunk/SophyaPI/ProgPI/w2ps.cc@ 2156

Last change on this file since 2156 was 1639, checked in by ansari, 24 years ago

correction du texte de help ds w2ps.cc - Reza 16/8/2001

  • Property svn:executable set to *
File size: 5.7 KB
RevLine 
[1524]1#include "machdefs.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream.h>
5#include <math.h>
6
7#include <typeinfo>
8
9#include <vector>
10#include <string>
11
12#include "piacmd.h"
13#include "nobjmgr.h"
14#include "pistdimgapp.h"
15
16
17// Module chargeable ds piapp - Commande de gestion de sortie PS
18
19// Declaration de la fonction d'activation et de desactivation du module
20extern "C" {
21void W2PSModule_init();
22void W2PSModule_end();
23}
24
25
26// Une classe commande-executor, permettant d'enregistrer de
27// nouvelles commandes a piapp
28class W2PSModuleExecutor : public CmdExecutor {
29public:
30 W2PSModuleExecutor();
31 virtual ~W2PSModuleExecutor();
32 // Execute s'occupe de l'execution effective des commandes
33 virtual int Execute(string& keyw, vector<string>& args, string& toks);
34protected:
35 string psfilename;
36 PSFile * mpsfile;
37};
38
39/* --Methode-- */
40W2PSModuleExecutor::W2PSModuleExecutor()
41{
42
43psfilename = "w2ps.ps";
44mpsfile = NULL;
45
46PIACmd * mpiac;
47NamedObjMgr omg;
48mpiac = omg.GetImgApp()->CmdInterpreter();
49
50// On enregistre deux nouvelles commandes
51string hgrp = "Graphics";
52// commande w2pssetfilename
53string kw = "pssetfilename";
[1639]54string usage = "pssetfilename: Sets current PostScript file name\n" ;
55usage += "Usage: pssetfilename FileName ";
[1524]56mpiac->RegisterCommand(kw, usage, this, hgrp);
57// commande w2psgetfilename
58kw = "psgetfilename";
[1639]59usage = "psgetfilename: Prints current PostScript file name \n" ;
60usage += "Usage: psgetfilename ";
[1524]61mpiac->RegisterCommand(kw, usage, this, hgrp);
62// commande w2psclosefile
63kw = "psclosefile";
[1639]64usage = "psclosefile: close current postscript file \n" ;
[1524]65usage += "Usage: w2psclosefile ";
66mpiac->RegisterCommand(kw, usage, this, hgrp);
67// commande w2ps
68kw = "w2ps";
69usage = "w2ps: Current Window To PostScript \n" ;
70usage += "Usage: w2ps ";
71mpiac->RegisterCommand(kw, usage, this, hgrp);
72// commande w2eps
73kw = "w2eps";
74usage = "w2eps: Current Window To EncapsulatedPostScript \n" ;
75usage += "Usage: w2eps EPSFileName";
76mpiac->RegisterCommand(kw, usage, this, hgrp);
77// commande imagcmap2eps
78kw = "imagcmap2ps";
79usage = "w2ps: Current Image+ColorMap To PostScript \n" ;
80usage += "Usage: imagcmap2ps ";
81mpiac->RegisterCommand(kw, usage, this, hgrp);
82// commande imagcmap2eps
83kw = "imagcmap2eps";
84usage = "imagcmap2eps: Current Image+ColorMap To EncapsulatedPostScript \n" ;
85usage += "Usage: imagcmap2eps EPSFileName";
86mpiac->RegisterCommand(kw, usage, this, hgrp);
87}
88
89/* --Methode-- */
90W2PSModuleExecutor::~W2PSModuleExecutor()
91{
92 if(mpsfile) delete mpsfile;
93}
94
95/* --Methode-- */
96int W2PSModuleExecutor::Execute(string& kw, vector<string>& tokens, string&)
97{
98
99NamedObjMgr omg;
100if (kw == "pssetfilename") {
101 if (tokens.size() < 1) {
102 cout << "Usage: pssetfilename PSFileName" << endl;
103 return(0);
104 }
105 if (mpsfile) delete mpsfile;
106 mpsfile = NULL;
107 psfilename = tokens[0];
108}
109else if (kw == "psgetfilename") {
110 cout << " W2PS: PSFileName= " << psfilename << endl;
111}
112else if (kw == "psclosefile") {
113 if (mpsfile) {
114 cout << "psclosefile: Closing file " << psfilename << endl;
115 delete mpsfile;
116 mpsfile = NULL;
117 psfilename = "w2ps.ps";
118 }
119}
120else if ( (kw == "w2ps") || (kw == "w2eps") ) {
121 PIStdImgApp* sapp = omg.GetImgApp();
122 if (sapp == NULL) {
123 cout << " W2PSModuleExecutor::Execute() No PIStdImgApp !" << endl;
124 return(0);
125 }
126 if (sapp->CurrentWindow() == NULL) {
127 cout << " W2PSModuleExecutor::Execute() No current window !" << endl;
128 return(0);
129 }
130 if (kw == "w2ps") {
131 if (mpsfile == NULL)
132 mpsfile = new PSFile(psfilename.c_str(), PI_Portrait, PI_A4, 2., 2.);
133 sapp->CurrentWindow()->PSPrint(mpsfile,0,0);
134 cout << " w2ps: Current window to PS file " << psfilename << endl;
135 }
136 else if (kw == "w2eps") {
137 if (tokens.size() < 1) {
138 cout << "Usage: w2eps EPSFileName" << endl;
139 return(0);
140 }
141 PSFile epsfile(tokens[0].c_str());
142 sapp->CurrentWindow()->PSPrint(&epsfile,0,0);
143 cout << " w2eps: Current window to EPS file " << tokens[0] << endl;
144 }
145}
146else if ( (kw == "imagcmap2ps") || (kw == "imagcmap2eps") ) {
147 PIStdImgApp* sapp = omg.GetImgApp();
148 if (sapp == NULL) {
149 cout << " W2PSModuleExecutor::Execute() No PIStdImgApp !" << endl;
150 return(0);
151 }
152 PIImage* curpimg = NULL;
153 if (sapp->CurrentBaseWdg())
154 curpimg = dynamic_cast<PIImage *>(sapp->CurrentBaseWdg());
155 if (curpimg == NULL) {
156 cout << " W2PSModuleExecutor::Execute() No current PIImage !" << endl;
157 return(0);
158 }
159 PSFile * cpsf = NULL;
160 PSFile * cepsf = NULL;
161 if (kw == "imagcmap2ps") {
162 if (mpsfile == NULL)
163 mpsfile = new PSFile(psfilename.c_str(), PI_Portrait, PI_A4, 2., 2.);
164 cpsf = mpsfile;
165 cout << " imagcmap2ps: Current image+colormap to PS file " << psfilename << endl;
166 }
167 else if (kw == "imagcmap2eps") {
168 if (tokens.size() < 1) {
169 cout << "Usage: imagcmap2eps EPSFileName" << endl;
170 return(0);
171 }
172 cepsf = new PSFile(tokens[0].c_str());
173 cpsf = cepsf;
174 cout << " imagcmap2eps: Current image+colormap to EPS file " << tokens[0] << endl;
175 }
[1533]176 double sx, sy;
177 sx = curpimg->XSize();
[1524]178 sy = curpimg->YSize() + sapp->CMapVW()->YSize() + 10;
[1533]179 cpsf->NewPage(sx, sy, PI_Auto);
180 curpimg->PSPrint(cpsf, -curpimg->XPos(), -curpimg->YPos());
181 sapp->CMapVW()->PSPrint(cpsf, -(sapp->CMapVW()->XPos()),
182 -(sapp->CMapVW()->YPos())+curpimg->YSize()+10,
183 sx/(double)sapp->CMapVW()->XSize(), 1.);
[1524]184
185 if (cepsf) delete cepsf;
186}
187
188return(0);
189
190}
191
192static W2PSModuleExecutor * piaw2psex = NULL;
193/* Nouvelle-Fonction */
194void W2PSModule_init()
195{
196// Fonction d'initialisation du module
197// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
198if (piaw2psex) delete piaw2psex;
199piaw2psex = new W2PSModuleExecutor;
200}
201
202/* Nouvelle-Fonction */
203void W2PSModule_end()
204{
205// Desactivation du module
206if (piaw2psex) delete piaw2psex;
207piaw2psex = NULL;
208}
209
Note: See TracBrowser for help on using the repository browser.