| [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 | 
|---|
| [3552] | 52 | string hgrp = "GraphicExport"; | 
|---|
| [1524] | 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 | } | 
|---|
| [2801] | 127 | sapp->CkEvt_LockMutex(); | 
|---|
| [1524] | 128 | if (sapp->CurrentWindow() == NULL) { | 
|---|
| [2801] | 129 | sapp->UnlockMutex(); | 
|---|
| [1524] | 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) { | 
|---|
| [2801] | 141 | sapp->UnlockMutex(); | 
|---|
| [1524] | 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 | } | 
|---|
| [2801] | 149 | sapp->UnlockMutex(); | 
|---|
| [1524] | 150 | } | 
|---|
|  | 151 | else 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; | 
|---|
| [2801] | 158 | sapp->CkEvt_LockMutex(); | 
|---|
| [1524] | 159 | if (sapp->CurrentBaseWdg()) | 
|---|
|  | 160 | curpimg = dynamic_cast<PIImage *>(sapp->CurrentBaseWdg()); | 
|---|
|  | 161 | if (curpimg == NULL) { | 
|---|
| [2801] | 162 | sapp->UnlockMutex(); | 
|---|
| [1524] | 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) { | 
|---|
| [2801] | 176 | sapp->UnlockMutex(); | 
|---|
| [1524] | 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 | } | 
|---|
| [1533] | 184 | double sx, sy; | 
|---|
|  | 185 | sx = curpimg->XSize(); | 
|---|
| [1524] | 186 | sy = curpimg->YSize() + sapp->CMapVW()->YSize() + 10; | 
|---|
| [1533] | 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.); | 
|---|
| [1524] | 192 |  | 
|---|
| [2801] | 193 | sapp->UnlockMutex(); | 
|---|
| [1524] | 194 | if (cepsf) delete cepsf; | 
|---|
|  | 195 | } | 
|---|
|  | 196 |  | 
|---|
|  | 197 | return(0); | 
|---|
|  | 198 |  | 
|---|
|  | 199 | } | 
|---|
|  | 200 |  | 
|---|
|  | 201 | static W2PSModuleExecutor * piaw2psex = NULL; | 
|---|
|  | 202 | /* Nouvelle-Fonction */ | 
|---|
|  | 203 | void W2PSModule_init() | 
|---|
|  | 204 | { | 
|---|
|  | 205 | // Fonction d'initialisation du module | 
|---|
|  | 206 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule()) | 
|---|
|  | 207 | if (piaw2psex) delete piaw2psex; | 
|---|
|  | 208 | piaw2psex = new W2PSModuleExecutor; | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
|  | 211 | /* Nouvelle-Fonction */ | 
|---|
|  | 212 | void W2PSModule_end() | 
|---|
|  | 213 | { | 
|---|
|  | 214 | // Desactivation du module | 
|---|
|  | 215 | if (piaw2psex) delete piaw2psex; | 
|---|
|  | 216 | piaw2psex = NULL; | 
|---|
|  | 217 | } | 
|---|
|  | 218 |  | 
|---|