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

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