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

Last change on this file since 4051 was 3552, checked in by ansari, 17 years ago

Petite amelioration aide en ligne, Reza 13/12/2008

  • Property svn:executable set to *
File size: 5.9 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 = "GraphicExport";
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 sapp->CkEvt_LockMutex();
128 if (sapp->CurrentWindow() == NULL) {
129 sapp->UnlockMutex();
130 cout << " W2PSModuleExecutor::Execute() No current window !" << endl;
131 return(0);
132 }
133 if (kw == "w2ps") {
134 if (mpsfile == NULL)
135 mpsfile = new PSFile(psfilename.c_str(), PI_Portrait, PI_A4, 2., 2.);
136 sapp->CurrentWindow()->PSPrint(mpsfile,0,0);
137 cout << " w2ps: Current window to PS file " << psfilename << endl;
138 }
139 else if (kw == "w2eps") {
140 if (tokens.size() < 1) {
141 sapp->UnlockMutex();
142 cout << "Usage: w2eps EPSFileName" << endl;
143 return(0);
144 }
145 PSFile epsfile(tokens[0].c_str());
146 sapp->CurrentWindow()->PSPrint(&epsfile,0,0);
147 cout << " w2eps: Current window to EPS file " << tokens[0] << endl;
148 }
149 sapp->UnlockMutex();
150}
151else if ( (kw == "imagcmap2ps") || (kw == "imagcmap2eps") ) {
152 PIStdImgApp* sapp = omg.GetImgApp();
153 if (sapp == NULL) {
154 cout << " W2PSModuleExecutor::Execute() No PIStdImgApp !" << endl;
155 return(0);
156 }
157 PIImage* curpimg = NULL;
158 sapp->CkEvt_LockMutex();
159 if (sapp->CurrentBaseWdg())
160 curpimg = dynamic_cast<PIImage *>(sapp->CurrentBaseWdg());
161 if (curpimg == NULL) {
162 sapp->UnlockMutex();
163 cout << " W2PSModuleExecutor::Execute() No current PIImage !" << endl;
164 return(0);
165 }
166 PSFile * cpsf = NULL;
167 PSFile * cepsf = NULL;
168 if (kw == "imagcmap2ps") {
169 if (mpsfile == NULL)
170 mpsfile = new PSFile(psfilename.c_str(), PI_Portrait, PI_A4, 2., 2.);
171 cpsf = mpsfile;
172 cout << " imagcmap2ps: Current image+colormap to PS file " << psfilename << endl;
173 }
174 else if (kw == "imagcmap2eps") {
175 if (tokens.size() < 1) {
176 sapp->UnlockMutex();
177 cout << "Usage: imagcmap2eps EPSFileName" << endl;
178 return(0);
179 }
180 cepsf = new PSFile(tokens[0].c_str());
181 cpsf = cepsf;
182 cout << " imagcmap2eps: Current image+colormap to EPS file " << tokens[0] << endl;
183 }
184 double sx, sy;
185 sx = curpimg->XSize();
186 sy = curpimg->YSize() + sapp->CMapVW()->YSize() + 10;
187 cpsf->NewPage(sx, sy, PI_Auto);
188 curpimg->PSPrint(cpsf, -curpimg->XPos(), -curpimg->YPos());
189 sapp->CMapVW()->PSPrint(cpsf, -(sapp->CMapVW()->XPos()),
190 -(sapp->CMapVW()->YPos())+curpimg->YSize()+10,
191 sx/(double)sapp->CMapVW()->XSize(), 1.);
192
193 sapp->UnlockMutex();
194 if (cepsf) delete cepsf;
195}
196
197return(0);
198
199}
200
201static W2PSModuleExecutor * piaw2psex = NULL;
202/* Nouvelle-Fonction */
203void W2PSModule_init()
204{
205// Fonction d'initialisation du module
206// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
207if (piaw2psex) delete piaw2psex;
208piaw2psex = new W2PSModuleExecutor;
209}
210
211/* Nouvelle-Fonction */
212void W2PSModule_end()
213{
214// Desactivation du module
215if (piaw2psex) delete piaw2psex;
216piaw2psex = NULL;
217}
218
Note: See TracBrowser for help on using the repository browser.