[2615] | 1 | #include "sopnamsp.h"
|
---|
[1524] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <stdlib.h>
|
---|
[2322] | 5 | #include <iostream>
|
---|
[1524] | 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
|
---|
| 21 | extern "C" {
|
---|
| 22 | void W2PSModule_init();
|
---|
| 23 | void W2PSModule_end();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | // Une classe commande-executor, permettant d'enregistrer de
|
---|
| 28 | // nouvelles commandes a piapp
|
---|
| 29 | class W2PSModuleExecutor : public CmdExecutor {
|
---|
| 30 | public:
|
---|
| 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);
|
---|
| 35 | protected:
|
---|
| 36 | string psfilename;
|
---|
| 37 | PSFile * mpsfile;
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | /* --Methode-- */
|
---|
| 41 | W2PSModuleExecutor::W2PSModuleExecutor()
|
---|
| 42 | {
|
---|
| 43 |
|
---|
| 44 | psfilename = "w2ps.ps";
|
---|
| 45 | mpsfile = NULL;
|
---|
| 46 |
|
---|
| 47 | PIACmd * mpiac;
|
---|
| 48 | NamedObjMgr omg;
|
---|
| 49 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
| 50 |
|
---|
| 51 | // On enregistre deux nouvelles commandes
|
---|
| 52 | string hgrp = "Graphics";
|
---|
| 53 | // commande w2pssetfilename
|
---|
| 54 | string kw = "pssetfilename";
|
---|
[1639] | 55 | string usage = "pssetfilename: Sets current PostScript file name\n" ;
|
---|
| 56 | usage += "Usage: pssetfilename FileName ";
|
---|
[1524] | 57 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 58 | // commande w2psgetfilename
|
---|
| 59 | kw = "psgetfilename";
|
---|
[1639] | 60 | usage = "psgetfilename: Prints current PostScript file name \n" ;
|
---|
| 61 | usage += "Usage: psgetfilename ";
|
---|
[1524] | 62 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 63 | // commande w2psclosefile
|
---|
| 64 | kw = "psclosefile";
|
---|
[1639] | 65 | usage = "psclosefile: close current postscript file \n" ;
|
---|
[1524] | 66 | usage += "Usage: w2psclosefile ";
|
---|
| 67 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 68 | // commande w2ps
|
---|
| 69 | kw = "w2ps";
|
---|
| 70 | usage = "w2ps: Current Window To PostScript \n" ;
|
---|
| 71 | usage += "Usage: w2ps ";
|
---|
| 72 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 73 | // commande w2eps
|
---|
| 74 | kw = "w2eps";
|
---|
| 75 | usage = "w2eps: Current Window To EncapsulatedPostScript \n" ;
|
---|
| 76 | usage += "Usage: w2eps EPSFileName";
|
---|
| 77 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 78 | // commande imagcmap2eps
|
---|
| 79 | kw = "imagcmap2ps";
|
---|
| 80 | usage = "w2ps: Current Image+ColorMap To PostScript \n" ;
|
---|
| 81 | usage += "Usage: imagcmap2ps ";
|
---|
| 82 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 83 | // commande imagcmap2eps
|
---|
| 84 | kw = "imagcmap2eps";
|
---|
| 85 | usage = "imagcmap2eps: Current Image+ColorMap To EncapsulatedPostScript \n" ;
|
---|
| 86 | usage += "Usage: imagcmap2eps EPSFileName";
|
---|
| 87 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /* --Methode-- */
|
---|
| 91 | W2PSModuleExecutor::~W2PSModuleExecutor()
|
---|
| 92 | {
|
---|
| 93 | if(mpsfile) delete mpsfile;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /* --Methode-- */
|
---|
| 97 | int W2PSModuleExecutor::Execute(string& kw, vector<string>& tokens, string&)
|
---|
| 98 | {
|
---|
| 99 |
|
---|
| 100 | NamedObjMgr omg;
|
---|
| 101 | if (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 | }
|
---|
| 110 | else if (kw == "psgetfilename") {
|
---|
| 111 | cout << " W2PS: PSFileName= " << psfilename << endl;
|
---|
| 112 | }
|
---|
| 113 | else 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 | }
|
---|
| 121 | else 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 | }
|
---|
| 147 | else 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 | }
|
---|
[1533] | 177 | double sx, sy;
|
---|
| 178 | sx = curpimg->XSize();
|
---|
[1524] | 179 | sy = curpimg->YSize() + sapp->CMapVW()->YSize() + 10;
|
---|
[1533] | 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.);
|
---|
[1524] | 185 |
|
---|
| 186 | if (cepsf) delete cepsf;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | return(0);
|
---|
| 190 |
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | static W2PSModuleExecutor * piaw2psex = NULL;
|
---|
| 194 | /* Nouvelle-Fonction */
|
---|
| 195 | void W2PSModule_init()
|
---|
| 196 | {
|
---|
| 197 | // Fonction d'initialisation du module
|
---|
| 198 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
| 199 | if (piaw2psex) delete piaw2psex;
|
---|
| 200 | piaw2psex = new W2PSModuleExecutor;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /* Nouvelle-Fonction */
|
---|
| 204 | void W2PSModule_end()
|
---|
| 205 | {
|
---|
| 206 | // Desactivation du module
|
---|
| 207 | if (piaw2psex) delete piaw2psex;
|
---|
| 208 | piaw2psex = NULL;
|
---|
| 209 | }
|
---|
| 210 |
|
---|