Index: /trunk/SophyaPI/PI/exclude
===================================================================
--- /trunk/SophyaPI/PI/exclude	(revision 31)
+++ /trunk/SophyaPI/PI/exclude	(revision 32)
@@ -18,2 +18,4 @@
 piwindowmac.cc
 piup_def.cc
+ex_dessin.cc
+sc_sample.cc
Index: /trunk/SophyaPI/PI/pibwdggen.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.cc	(revision 31)
+++ /trunk/SophyaPI/PI/pibwdggen.cc	(revision 32)
@@ -2,4 +2,5 @@
 
 #include "pibwdggen.h"
+#include "psfile.h"
 
 // Les methodes de la classe  PIBWdgGen
@@ -10,4 +11,5 @@
 PIWdg(par, nom, sx, sy, px, py)
 {
+mPSOut=NULL;
 }
 
@@ -115,2 +117,16 @@
 }
 
+
+/* --Methode-- */
+void PIBaseWdgGen::PSPrint(PSFile * psf, int ofx, int ofy)
+{
+if(!psf) return;
+mPSOut = psf;
+psf->NewBloc((float)(ofx+XPos()), (float)(ofy+YPos()),
+	     (float)XSize(),(float)YSize(),
+	     (float)XSize(),(float)YSize());
+Draw();
+psf->EndBloc();
+mPSOut=NULL;
+}
+
Index: /trunk/SophyaPI/PI/pibwdggen.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.h	(revision 31)
+++ /trunk/SophyaPI/PI/pibwdggen.h	(revision 32)
@@ -7,17 +7,23 @@
 #include "pibwdggen.h"
 
+
 enum PIKeyModifier { PIKM_Blank = 0, PIKM_Shift = 1, PIKM_Alt = 2, PIKM_Cntl = 4 } ; 
 
-enum PIColors  { PI_Black = 0, PI_White = 1,  PI_Grey = 2,
+enum PIColors  { PI_NotDefColor = -1,
+                 PI_Black = 0, PI_White = 1,  PI_Grey = 2,
                  PI_Red = 3, PI_Blue = 4, PI_Green = 5,  
                  PI_Yellow = 6, PI_Magenta =7 }; 
 
-enum PIFontSize { PI_SmallSizeFont = 1, PI_NormalSizeFont = 2, PI_BigSizeFont = 3 };
+enum PIFontSize { PI_NotDefFontSize = -1, 
+                  PI_SmallSizeFont = 1, PI_NormalSizeFont = 2, PI_BigSizeFont = 3 };
 
-enum PIFontAtt { PI_RomanFont = 1, PI_BoldFont = 2, PI_ItalicFont = 4 };
+enum PIFontAtt { PI_NotDefFontAtt = -1,
+                 PI_RomanFont = 1, PI_BoldFont = 2, PI_ItalicFont = 4 };
 
-enum PILineAtt { PI_NormalLine = 0, PI_ThinLine = 1, PI_ThickLine = 2 };
+enum PILineAtt { PI_NotDefLineAtt = -1,
+                 PI_NormalLine = 0, PI_ThinLine = 1, PI_ThickLine = 2 };
 
-enum PIMarker  { PI_DotMarker = 0, PI_PlusMarker=1, PI_CrossMarker=2,  
+enum PIMarker  { PI_NotDefMarker = -1,
+                 PI_DotMarker = 0, PI_PlusMarker=1, PI_CrossMarker=2,  
                  PI_CircleMarker=3, PI_FCircleMarker=4,
                  PI_BoxMarker=5, PI_FBoxMarker=6,
@@ -109,6 +115,13 @@
   virtual void       Ptr3Move(int x, int y);
   virtual void       Keyboard(int key, PIKeyModifier kmod);
+
+// PostScript output
+  virtual void       PSPrint(PSFile * psf, int ofx = 0, int ofy = 0); 
+
+protected:
+  PSFile * mPSOut;  /* Fichier PostScript eventuel */
 };
 
 
 #endif /* PIBWDGGEN_H_SEEN */
+
Index: /trunk/SophyaPI/PI/pibwdgx.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdgx.cc	(revision 31)
+++ /trunk/SophyaPI/PI/pibwdgx.cc	(revision 32)
@@ -12,4 +12,6 @@
 #include "pixtbaseP.h"
 #include "pixtbase.h"
+
+#include "psfile.h"
 
 
@@ -132,4 +134,5 @@
 void PIBaseWdgX::EraseWindow()
 {
+if(mPSOut) return;
 XClearWindow   (XtDisplay(XtWdg()),XtWindow(XtWdg()) );
 return;
@@ -139,4 +142,8 @@
 void PIBaseWdgX::DrawString(int x, int y, char* s, int pos)
 {
+if(mPSOut){
+mPSOut->DrawString((float)x,(float)y,s,mFCol,mFAtt,mFSize); /* PIFontSize ?? */
+}
+else
 XDrawString (XtDisplay (XtWdg()),XtWindow(XtWdg()), 
                   DefGC(), x, y, s, strlen(s));
@@ -148,4 +155,9 @@
 void PIBaseWdgX::DrawLine(int x1, int y1, int x2, int y2)
 {
+if(mPSOut){
+mPSOut->DrawLine((float)x1,(float)y1,(float)x2,(float)y2,
+		 mFCol,mLAtt);
+}
+else
 XDrawLine(XtDisplay (XtWdg()), XtWindow(XtWdg()), DefGC(), x1, y1, x2, y2);
 return;
@@ -156,8 +168,12 @@
 void PIBaseWdgX::DrawBox(int x0, int y0, int dx, int dy)
 {
+if(mPSOut)
+mPSOut->DrawBox((float)x0,(float)y0,(float)dx,(float)dy,mFCol,mLAtt);
+else{
 if (dx < 0)  { x0 += dx;  dx = -dx; }
 if (dy < 0)  { y0 += dy;  dy = -dy; }
 XDrawRectangle(XtDisplay (XtWdg()), XtWindow(XtWdg()), 
                DefGC(), x0, y0, dx, dy);
+}
 return;
 }
@@ -166,8 +182,12 @@
 void PIBaseWdgX::DrawFBox(int x0, int y0, int dx, int dy)
 {
+if(mPSOut)
+mPSOut->DrawFBox((float)x0,(float)y0,(float)dx,(float)dy);
+else{
 if (dx < 0)  { x0 += dx;  dx = -dx; }
 if (dy < 0)  { y0 += dy;  dy = -dy; }
 XFillRectangle(XtDisplay (XtWdg()), XtWindow(XtWdg()), 
                DefGC(), x0, y0, dx, dy);
+}
 return;
 }
@@ -176,4 +196,7 @@
 void PIBaseWdgX::DrawCircle(int x0, int y0, int r)
 {
+if(mPSOut)
+mPSOut->DrawCircle((float)x0,(float)y0,(float)r,mFCol,mLAtt);
+else
 XDrawArc(XtDisplay (XtWdg()), XtWindow(XtWdg()), DefGC(),
          x0-r, y0-r, 2*r, 2*r, 0, 360*64);
@@ -184,4 +207,7 @@
 void PIBaseWdgX::DrawFCircle(int x0, int y0, int r)
 {
+if(mPSOut)
+mPSOut->DrawFCircle((float)x0,(float)y0,(float)r,mFCol,mFCol,mLAtt);
+else
 XFillArc(XtDisplay (XtWdg()), XtWindow(XtWdg()), DefGC(),
          x0-r, y0-r, 2*r, 2*r, 0, 360*64);
@@ -198,5 +224,20 @@
 XPoint *pxp;
 int i;
-
+float *xtmp;
+float *ytmp;
+
+if(mPSOut)
+{
+xtmp = (float*)malloc(n*sizeof(float));
+ytmp = (float*)malloc(n*sizeof(float));
+for(i=0;i<n;i++){
+  xtmp[i] = (float)x[i];
+  ytmp[i] = (float)y[i];
+}
+mPSOut->DrawPolygon(xtmp,ytmp,n,mFCol,mLAtt);
+free(xtmp);
+free(ytmp);
+}
+else {
 if (n <= 0)  return;
 if (n > NMXXPOINTS)  pxp = new XPoint[n];
@@ -205,4 +246,5 @@
 XDrawLines(XtDisplay(XtWdg()), XtWindow(XtWdg()), DefGC(), pxp, n, CoordModePrevious);
 if (n > NMXXPOINTS)  delete[] pxp;
+}
 return;
 }
@@ -215,5 +257,21 @@
 XPoint *pxp;
 int i;
-
+float *xtmp;
+float *ytmp;
+
+if(mPSOut)
+{
+xtmp = (float*)malloc(n*sizeof(float));
+ytmp = (float*)malloc(n*sizeof(float));
+for(i=0;i<n;i++){
+  xtmp[i] = (float)x[i];
+  ytmp[i] = (float)y[i];
+}
+mPSOut->DrawFPolygon(xtmp,ytmp,n,mFCol,mFCol,mLAtt);
+free(xtmp);
+free(ytmp);
+}
+else
+{
 if (n <= 0)  return;
 if (n > NMXXPOINTS)  pxp = new XPoint[n];
@@ -223,4 +281,5 @@
                         Complex, CoordModePrevious);
 if (n > NMXXPOINTS)  delete[] pxp;
+}
 return;
 }
@@ -233,5 +292,8 @@
 int x[4],y[4];
 PILineAtt clatt;
-
+if(mPSOut)
+mPSOut->DrawMarker((float)x0,(float)y0,mMrk,mFCol);
+else
+{
 if (mMrk == PI_DotMarker)
   XDrawPoint(XtDisplay(XtWdg()), XtWindow(XtWdg()), DefGC(), x0, y0);
@@ -279,4 +341,5 @@
   SelLine(clatt);
   }
+}
 return;
 }
@@ -286,5 +349,21 @@
 {
 int i;
-
+float *xtmp;
+float *ytmp;
+
+if(mPSOut)
+{
+xtmp = (float*)malloc(n*sizeof(float));
+ytmp = (float*)malloc(n*sizeof(float));
+for(i=0;i<n;i++){
+  xtmp[i] = (float)x[i];
+  ytmp[i] = (float)y[i];
+}
+mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol);
+free(xtmp);
+free(ytmp);
+}
+else
+{
 if (n <= 0)  return;
 if (mMrk == PI_DotMarker)
@@ -299,4 +378,5 @@
   }
 else for(i=0; i<n; i++) DrawMarker(x[i], y[i]);
+}
 }
 
Index: /trunk/SophyaPI/PI/picmap.h
===================================================================
--- /trunk/SophyaPI/PI/picmap.h	(revision 31)
+++ /trunk/SophyaPI/PI/picmap.h	(revision 32)
@@ -1,2 +1,5 @@
+#ifndef PICMAP_H_SEEN
+#define PICMAP_H_SEEN
+
 #include "pisysdep.h"
 #include PICMAPNTV_H
@@ -12,2 +15,4 @@
 };
 
+#endif
+
Index: /trunk/SophyaPI/PI/picontainergen.cc
===================================================================
--- /trunk/SophyaPI/PI/picontainergen.cc	(revision 31)
+++ /trunk/SophyaPI/PI/picontainergen.cc	(revision 32)
@@ -23,4 +23,14 @@
   for(int i=0; i<mNCh; i++)  delete mChilds[i];
 delete[] mChilds;
+}
+
+/* --Methode-- */
+void PIContainerGen::PSPrint(PSFile *psf, int ofx, int ofy)
+{
+int i;
+if (!psf)  return;
+if (!Visible())  return;
+for(i=0; i<mNCh; i++)  mChilds[i]->PSPrint(psf, ofx+XPos(), ofy+YPos()); 
+return;
 }
 
Index: /trunk/SophyaPI/PI/picontainergen.h
===================================================================
--- /trunk/SophyaPI/PI/picontainergen.h	(revision 31)
+++ /trunk/SophyaPI/PI/picontainergen.h	(revision 32)
@@ -18,4 +18,6 @@
   virtual long         kind() {return ClassId; }
 
+  virtual void         PSPrint(PSFile *psf, int ofx=0, int ofy=0);
+
   virtual void         Show();
   virtual void         Hide();
Index: /trunk/SophyaPI/PI/pipixmapx.cc
===================================================================
--- /trunk/SophyaPI/PI/pipixmapx.cc	(revision 31)
+++ /trunk/SophyaPI/PI/pipixmapx.cc	(revision 32)
@@ -6,4 +6,5 @@
 
 #include "pipixmapx.h"
+#include "psfile.h"
 
 static  GC    mygc;
@@ -59,5 +60,11 @@
 void PIPixmapX::Draw()
 {
-Draw(0, 0, XSize(), YSize());
+if(mPSOut)
+  if(pixmap) 
+    mPSOut->Image(0, 0, (float)XSize(), (float)YSize(), nx, ny, pixmap, cmap);
+  else
+    return; /* pour l'instant */
+else
+  Draw(0, 0, XSize(), YSize());
 }
 
Index: /trunk/SophyaPI/PI/piwdggen.cc
===================================================================
--- /trunk/SophyaPI/PI/piwdggen.cc	(revision 31)
+++ /trunk/SophyaPI/PI/piwdggen.cc	(revision 32)
@@ -5,4 +5,5 @@
 #include "picontainergen.h"
 
+#include "psfile.h"
 
 /* --Methode-- */
@@ -44,4 +45,19 @@
 }
 
+/* --Methode-- */
+void PIWdgGen::PSPrint(PSFile *psf, int ofx, int ofy)
+{
+char str[256];
+
+if (!psf) return;
+psf->NewBloc((float)ofx+XPos(), (float)ofy+YPos(), (float)XSize(), (float)YSize(),
+             (float)XSize(), (float)YSize());
+psf->DrawBox(0., 0., (float)XSize(), (float)YSize());
+sprintf(str,"PIWdgGen::PSPrint() Kind=%ld Name= %s", kind(), Nom().c_str());
+psf->DrawString(5., 5., str);
+psf->EndBloc();
+
+return;
+}
 
 /* --Methode-- 
Index: /trunk/SophyaPI/PI/piwdggen.h
===================================================================
--- /trunk/SophyaPI/PI/piwdggen.h	(revision 31)
+++ /trunk/SophyaPI/PI/piwdggen.h	(revision 32)
@@ -20,4 +20,5 @@
 };
 
+class PSFile;
 class PIContainerGen;
 class PIWdgGen : public PIMsgHandler
@@ -60,4 +61,6 @@
   virtual void           GetScreenPos(int & spx, int & spy);
 
+  virtual void           PSPrint(PSFile *psf, int ofx=0, int ofy=0);
+
 protected:
   PIContainerGen        *parent;
Index: /trunk/SophyaPI/PI/piwindowgen.cc
===================================================================
--- /trunk/SophyaPI/PI/piwindowgen.cc	(revision 31)
+++ /trunk/SophyaPI/PI/piwindowgen.cc	(revision 32)
@@ -1,4 +1,4 @@
 #include "piwindowgen.h"
-
+#include "psfile.h"
 
 /* --Methode-- */
@@ -15,4 +15,14 @@
 PIWindowGen::~PIWindowGen()
 {}
+
+/* --Methode-- */
+void PIWindowGen::PSPrint(PSFile *psf, int ofx, int ofy)
+{
+if (!psf) return;
+int ori;
+ori = (XSize() > YSize()) ? LANDSCAPE : PORTRAIT ;
+psf->NewPage((float)XSize(), (float)YSize(),ori);
+PIContainerGen::PSPrint(psf, ofx, ofy);
+}
 
 
Index: /trunk/SophyaPI/PI/piwindowgen.h
===================================================================
--- /trunk/SophyaPI/PI/piwindowgen.h	(revision 31)
+++ /trunk/SophyaPI/PI/piwindowgen.h	(revision 32)
@@ -22,4 +22,6 @@
   virtual long      kind() {return ClassId; }
 
+  virtual void      PSPrint(PSFile *psf, int ofx=0, int ofy=0);
+
   inline  void      AutoHideOnClose(bool ahc=true) { mAHC = ahc; }
 
Index: /trunk/SophyaPI/PI/psfile.cc
===================================================================
--- /trunk/SophyaPI/PI/psfile.cc	(revision 32)
+++ /trunk/SophyaPI/PI/psfile.cc	(revision 32)
@@ -0,0 +1,720 @@
+/*
+ *   PSFile.cc
+ *   
+ *   19/06/96
+ *
+ *
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <time.h>
+
+#include "psfile.h"
+
+
+
+
+
+extern float cm2pt(float x);
+
+
+/*
+ *   Premier constructeur :
+ *     Creation d'un fichier .ps ou .eps
+ *
+ */
+PSFile::PSFile (char *FileName = NULL, float Tx = 0, float Ty = 0,
+		float Dx = 0, float Dy = 0) {
+
+  //    extern int FileEmpty;
+  //    extern int BlocActive;
+  //    extern int PageActive;
+
+    /* Si une bounding box est precisee, on produit du .eps */
+    if ( (Tx != 0) && (Ty != 0) )  isEPS = 1;
+    else   isEPS = 0;
+
+
+    /* Nom du fichier */
+    if ( FileName != NULL ) {
+	mPSFileName = new ( char[strlen(FileName)+1] );
+	strcpy(mPSFileName, FileName);
+    }
+    else {
+	mPSFileName = new ( char[11] );
+	strncpy(mPSFileName, "unnamed.ps", 11);
+    }
+
+    /* Ouverture du fichier, en mode w+ (tout est ecrase) */
+    if ( (mPSFile = fopen(FileName, "w+")) == NULL){
+	  perror (FileName);
+	  return;
+    }
+
+    /* Initialisations... */
+    mFormat.X0 = 0;  /* Pr le moment ... */
+    mFormat.Y0 = 0;
+    mFormat.orientation = LANDSCAPE;
+    if ( (Tx == 0) || (Ty == 0) ) {
+	mFormat.Tx = PAGE_WIDTH;
+	mFormat.Ty = PAGE_HEIGHT;
+    }
+    else {
+      mFormat.Tx = Tx;
+      mFormat.Ty = Ty;
+    }
+    if ( (Dx == 0) || (Dy == 0) ) {
+	mFormat.Dx = mFormat.Tx;
+	mFormat.Dy = mFormat.Ty;
+    }
+    else {
+      mFormat.Dx = Dx;
+      mFormat.Dy = Dy;
+    }
+    PageCounter  = 0;
+    mDrawColor = PI_Black;
+    mFillColor = PI_Black;
+    mFontAtt   = PI_RomanFont;
+    mFontSize  = PI_NormalSizeFont;
+    mLineAtt   = PI_NormalLine;
+    mMarker    = PI_DotMarker;
+
+    /* Ecriture de l'en tete */
+    WriteHeader();
+}
+
+/*
+ * Second constructeur 
+ *
+ * Extraction d'un bloc ou d'une page
+ * d'un fichier deja existant
+ *
+ */
+//PSFile::PSFile(char * FileName, PSFile *File = NULL , int PageNum = 0, 
+//	       int BlocNum = 0) {
+//
+//    PageList::iterator PIt;
+//    char *buffer;
+//
+//    if ( (File == NULL) || (PageNum == 0) ) {
+//	fprintf(stderr, "PSFile::PSFile : args incorrects\n");
+//	return;
+//    }
+//
+// 
+//    if ( FileName != NULL ) {
+//	mPSFileName = new ( char[strlen(FileName)+1] );
+//	strcpy(mPSFileName, FileName);
+//    }
+//    else {
+//	mPSFileName = new ( char[11] );
+//	strncpy(mPSFileName, "unnamed.ps", 11);
+//    }
+//
+//
+//    if ( PageCounter >= PageNum  ) {
+//	for(PIt = (File)->mPageList.begin(); PIt < (File)->mPageList.end(); 
+//	    PIt++);
+//	PIt--;
+//    }
+//    else {
+//	fprintf(stderr, "Page %d inexistante\n", PageNum);
+//	return;
+//    }
+//
+//    if (BlocNum != 0) {
+//	if ( (*PIt).BlocCounter >= BlocNum ) {
+//	    for(BIt=(*PIt).mBlocList.begin();PIt<(*PIt).mBlocList.end();BIt++);
+//	    BIt--;
+//	}
+//	else {
+//	    fprintf(stderr,"Bloc %d, (Page %d) inexistant\n",BlocNum,PageNum);
+//	    return;
+//	}
+//    }
+//
+//    if ( (mPSFile = fopen(FileName, "w+")) == NULL){
+//	  perror (FileName);
+//	  return;
+//    }
+//
+//   mFormat.X0 = 0;
+//    mFormat.Y0 = 0;
+//   mFormat.orientation = PORTRAIT;
+//    if ( (Tx == 0) || (Ty == 0) ) {
+//	mFormat.Tx = PAGE_WIDTH;
+//	mFormat.Ty = PAGE_HEIGHT;
+//    }
+//    if ( (Dx == 0) || (Dy == 0) ) {
+//	mFormat.Dx = mFormat.Tx;
+//	mFormat.Dy = mFormat.Ty;
+//    }
+//    PageCounter  = 0;
+//    mDrawColor = PI_Black;
+//    mFillColor = PI_Black;
+//    mFontAtt   = PI_RomanFont;
+//    mFontSize  = PI_NormalSizeFont;
+//    mLineAtt   = PI_NormalLine;
+//    mMarker    = PI_DotMarker;
+//
+//    WriteHeader();
+//    WriteNewPage(&(*PIt));
+//    if(BlocNum != 0)
+//	WriteNewBloc(&(*BIt));
+//
+//    PSScan(PageNum, BlocNum, off_t limites[2]);
+//    
+//
+//    
+//    buffer = (char*)malloc(BUFSZ*sizeof(char));
+//    
+//    return;
+//}
+
+
+
+
+/* 
+ * Destructeur
+ *
+ */
+PSFile::~PSFile () {
+    extern int FileEmpty;
+    extern int BlocActive;
+    extern int PageActive;
+
+    /* On ferme tout ce qui ne l'est pas */
+    if (BlocActive) PSFile::EndBloc();
+    if (PageActive) PSFile::EndPage();
+
+    /* Si le fichier est vide, on le detruit */
+    if (FileEmpty) remove(mPSFileName);
+
+    /* Sinon, on ecrit le "Trailer" et on ferme */
+    else {
+	WriteTrailer();
+	fclose (mPSFile);
+    }
+}
+
+
+int   PSFile::IsEPS(){
+
+    return(isEPS);
+}
+
+Format *PSFile::GetFormat() {
+
+    Format *form = (Format*)malloc(sizeof(Format));
+
+    form->X0 = mFormat.X0;
+    form->Y0 = mFormat.Y0;
+    form->Tx = mFormat.Tx;
+    form->Ty = mFormat.Ty;
+    form->Dx = mFormat.Dx;
+    form->Dy = mFormat.Dy;
+    form->orientation = mFormat.orientation;
+    return(form);
+}
+
+char* PSFile::GetFileName() {
+
+    return(mPSFileName);
+}
+
+PIColors PSFile::GetDrawColor() {
+
+    return(mDrawColor);
+}
+
+PIColors PSFile::GetFillColor() {
+
+    return(mFillColor);
+}
+
+PIFontAtt PSFile::GetFontAtt() {
+
+    return(mFontAtt);
+}
+
+PIFontSize PSFile::GetFontSize() {
+
+    return(mFontSize);
+}
+
+PILineAtt PSFile::GetLineAtt() {
+
+    return(mLineAtt);
+}
+
+PIMarker PSFile::GetMarker() {
+
+    return(mMarker);
+}
+
+void  PSFile::NewPage(float Dx, float Dy, int orient) {
+
+    extern int PageActive;
+    extern int PageEmpty;
+    Page   mNewPage;
+
+    /* On ferme ce qui doit l'etre ... */
+    if (PageActive) PSFile::EndPage();
+
+    mNewPage.num = ++PageCounter;
+    mNewPage.BlocCounter = 0;
+    mNewPage.format.X0 = 0;
+    mNewPage.format.Y0 = 0;
+    mNewPage.format.Tx = mFormat.Tx;
+    mNewPage.format.Ty = mFormat.Ty;
+    mNewPage.format.Dx = Dx;
+    mNewPage.format.Dy = Dy;
+    mNewPage.format.orientation = orient;
+
+    /* On enregistre la position du debut --> AVANT D'ECRIRE */
+    mNewPage.offset.begin  = ftell(mPSFile);
+
+    /* On met a jour le fichier */
+    WriteNewPage(&mNewPage);
+
+    /* On ajoute cette nouvelle page a la liste des pages du fichier */
+    mPageList.push_back(mNewPage);
+
+    PageActive = 1;
+    PageEmpty  = 1;
+}
+
+
+
+void  PSFile::EndPage() {
+
+    extern int PageActive;
+    extern int BlocActive;
+    extern int PageEmpty;
+    extern int FileEmpty;
+    PageList::iterator it;
+
+    /* Si rien a fermer, on s'en va */
+    if ( ! PageActive ) return;
+
+    /* Si un bloc non ferme, on appelle EndBloc */
+    if (BlocActive) PSFile::EndBloc();
+    
+    /* Si la page est vide, on la detruit */
+    if (PageEmpty) {
+	it = mPageList.end(); it--;
+	/* Si 1 seule page ds fichier, retour au debut */
+	if ( it == mPageList.begin() )
+	    fseek(mPSFile, (*it).offset.begin, SEEK_SET);
+	/* Sinon, on retourne a la fin de la page precedente */
+	else {
+	    it--;
+	    fseek(mPSFile, (*it).offset.end, SEEK_SET);
+	    it++;
+	}
+	mPageList.erase(it);
+	PageCounter--;
+    }
+    /* Sinon, Ok, on met a jour le fichier  */
+    else {
+	it = mPageList.end(); it--;
+	(*it).offset.end = ftell(mPSFile);
+	WriteEndPage(&(*it));
+	FileEmpty = 0;
+    }
+    PageActive = 0;
+}
+
+
+void  PSFile::NewBloc(float x0, float y0, float Tx, float Ty,
+			      float Dx, float Dy){
+    extern int BlocActive;
+    extern int PageActive;
+    extern int BlocEmpty;
+    Bloc   mNewBloc;
+    PageList::iterator it;
+
+    /* Si pas de page, on s'en va */
+    if (!PageActive) return;
+
+    /* On ferme le bloc precedent (Pas de Bloc-gigognes ! ) */
+    if (BlocActive) PSFile::EndBloc();
+
+    it = mPageList.end(); it --;
+    /* On remplit mNewBloc */
+    mNewBloc.num = ++(*it).BlocCounter;
+    mNewBloc.format.X0 = x0;
+    mNewBloc.format.Y0 = y0;
+    mNewBloc.format.Tx = Tx;
+    mNewBloc.format.Ty = Ty;
+    mNewBloc.format.Dx = Dx;
+    mNewBloc.format.Dy = Dy;
+    mNewBloc.format.orientation = 0;    /* Pr l'inst, blk non orient */
+    mNewBloc.offset.begin = ftell(mPSFile);
+
+    /* On met a jour le fichier */
+    WriteNewBloc(&mNewBloc);
+
+    /* On met a jour la liste des blocs */
+    (*it).mBlocList.push_back(mNewBloc);
+
+    BlocActive = 1;
+    BlocEmpty  = 1;
+}
+
+
+void  PSFile::EndBloc() {
+    extern int BlocActive;
+    extern int BlocEmpty;
+    extern int PageEmpty;
+    PageList::iterator  PIt;
+    BlocList::iterator  BIt;
+
+    /* On verifie qu'un bloc ouvert existe bien */
+    if ( ! BlocActive ) return;
+
+    /* Si le bloc est vide, on le detruit */
+    if (BlocEmpty) {
+	PIt = mPageList.end(); PIt--;
+	BIt = (*PIt).mBlocList.end(); BIt--;
+	/* Si 1 seul bloc --> debut */
+	if ( BIt == (*PIt).mBlocList.begin()) {
+	    fseek(mPSFile,(*BIt).offset.begin, SEEK_SET);
+	}
+	/* Sinon, --> fin du bloc precedent */
+	else {
+	    BIt--;
+	    fseek(mPSFile, (*BIt).offset.end, SEEK_SET);
+	    BIt++;
+	}   
+	(*PIt).mBlocList.erase(BIt);
+	(*PIt).BlocCounter--;
+    }
+    /* Sinon, Ok met a jour le fichier */
+    else {
+	PIt = mPageList.end(); PIt--;
+	BIt = (*PIt).mBlocList.end(); BIt--;
+	(*BIt).offset.end = ftell(mPSFile);
+	WriteEndBloc(&(*BIt));
+	PageEmpty = 0;
+    }
+    
+    BlocActive = 0;
+}
+
+
+void  PSFile::DrawString  (float x,  float y, char *s, 
+		   PIColors DrawColor  = PI_NotDefColor, 
+		   PIFontAtt FontAtt   = PI_NotDefFontAtt, 
+		   int FontSize        = 8) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+    int change = 0;
+
+    /* Couleurs */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+        WriteSetColor(mDrawColor);
+    }
+
+    /* Choix des fontes */
+    if ( (FontAtt != PI_NotDefFontAtt) || (FontAtt != mFontAtt) ) {
+	mFontAtt = FontAtt;
+	change = 1;}
+    if ( (FontSize != PI_NotDefFontSize) || (FontSize != mFontSize) ) {
+	mFontSize = FontSize;
+	change = 1;}
+    if (change)
+	WriteSetFont(mFontAtt, mFontSize);
+
+    WriteDrawString(x, y, s);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawLine    (float x1, float y1, float x2, float y2, 
+		   PIColors DrawColor  = PI_NotDefColor,
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Couleurs */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(mDrawColor);
+    }
+
+    /* Dessin */
+    WriteDrawLine(x1, y1, x2, y2);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+
+void  PSFile::DrawBox     (float x0, float y0, float Tx, float Ty, 
+		   PIColors  DrawColor = PI_NotDefColor,
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Changement couleurs ? */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(mDrawColor);
+    }
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* On dessine */
+    WriteDrawBox(x0, y0, Tx, Ty);
+    
+    /* Le fichier n'est plus vide */
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawFBox    (float x0, float y0, float Tx, float Ty, 
+		   PIColors DrawColor  = PI_NotDefColor,
+		   PIColors FillColor  = PI_NotDefColor, 
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Dessin du fond */
+    if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) )
+	mFillColor = FillColor;
+    WriteSetColor(mFillColor);
+    WriteDrawFBox(x0, y0, Tx, Ty);
+    WriteSetColor(mDrawColor);
+
+    /* Dessin du contour (s'il y a lieu) */
+    if ( (DrawColor != PI_NotDefColor) && (FillColor != DrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(DrawColor);
+	WriteDrawBox(x0, y0, Tx, Ty);
+    }
+    /* Le fichier n'est plus vide */
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawCircle  (float x0, float y0, float r, 
+		   PIColors DrawColor  = PI_NotDefColor,
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Couleurs */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(DrawColor);
+    }
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Dessin */
+    WriteDrawCircle(x0, y0, r);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawFCircle (float x0, float y0, float r,
+		   PIColors DrawColor  = PI_NotDefColor,
+		   PIColors FillColor  = PI_NotDefColor, 
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Dessin du fond */
+    if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ){
+	mFillColor = FillColor;
+	WriteSetColor(FillColor);
+    }
+    WriteDrawFCircle(x0, y0, r);
+
+    /* Dessin du contour (s'il y a lieu) */
+    if ( (DrawColor != PI_NotDefColor) && (FillColor != DrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(DrawColor);
+	WriteDrawCircle(x0, y0, r);
+    }    
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawPolygon (float *x, float *y, int n,
+		   PIColors DrawColor  = PI_NotDefColor, 
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+    //    int change = 0;
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Couleur */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(DrawColor);
+    }
+    
+    /* On dessine ; ici*/
+    WriteDrawPolygon (x, y, n);
+    
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawFPolygon(float *x, float *y, int n,
+		   PIColors DrawColor  = PI_NotDefColor,
+		   PIColors FillColor  = PI_NotDefColor,
+		   PILineAtt LineAtt   = PI_NotDefLineAtt) {
+
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Line Att */
+    if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) {
+        mLineAtt = LineAtt;
+	WriteSetLineWidth(mLineAtt);
+    }
+
+    /* Dessin du fond... */
+    if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ) {
+	mFillColor = FillColor;
+	WriteSetColor(FillColor);
+    }
+    WriteDrawFPolygon(x, y, n);
+
+    /* ...puis du contour (s'il y a lieu) */
+    if ( (DrawColor != PI_NotDefColor) && (DrawColor != FillColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(DrawColor);
+	WriteDrawPolygon(x, y, n);
+    }
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+
+void  PSFile::DrawMarker  (float x0, float y0,
+		   PIMarker MrkType    = PI_NotDefMarker,   
+		   PIColors DrawColor  = PI_NotDefColor) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+
+    /* Couleurs */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(mDrawColor);
+    }
+
+    /* Marker */
+    if (MrkType != PI_NotDefMarker)
+	mMarker = MrkType;
+
+    /* Dessin */
+    WriteDrawMarker(x0, y0);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+
+void  PSFile::DrawMarkers (float *x0, float *y0, int n,
+		   PIMarker MrkType    = PI_NotDefMarker,
+		   PIColors DrawColor  = PI_NotDefColor) {
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    /* Couleurs */
+    if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) {
+	mDrawColor = DrawColor;
+	WriteSetColor(mDrawColor);
+    }    
+
+    /* Marker */
+    if (MrkType != PI_NotDefMarker)
+	mMarker = MrkType;
+
+    /* Dessin */
+    WriteDrawMarkers(x0, y0, n);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+void PSFile::Image(float x0, float y0, float Tx, float Ty,
+		   int Nx, int Ny,
+		   unsigned char *Pict, 
+		   PIColorMap *mMap) {
+
+    extern int BlocEmpty;
+    extern int PageEmpty;
+
+    WriteImage(x0, y0, Tx, Ty, Nx, Ny, Pict,mMap);
+
+    BlocEmpty = 0;
+    PageEmpty = 0;
+}
+
+/* 
+ *  Une fonction de conversion qui sert une fois
+ *
+ */
+
+float cm2pt(float x) {
+    return (x*28.35);
+}
+
+
+    /* Logique de controle */
+    static int FileEmpty = 1;
+    static int PageEmpty;
+    static int BlocEmpty;
+    static int BlocActive;
+    static int PageActive;
Index: /trunk/SophyaPI/PI/psfile.h
===================================================================
--- /trunk/SophyaPI/PI/psfile.h	(revision 32)
+++ /trunk/SophyaPI/PI/psfile.h	(revision 32)
@@ -0,0 +1,215 @@
+#ifndef PSFILE_H_SEEN
+#define PSFILE_H_SEEN
+
+/*
+ *  PSFile.h
+ * 
+ *  14/06/96, 19/06/96
+ *
+ *  Gestion des fichier .ps et .eps
+ *
+ *     - L'unite de mesure est lUnite Courante (UC)
+ *        Au depart, 1UC == 1cm 
+ *     - Les reperes sont orientes a la maniere XWindow
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "pisysdep.h"
+
+#include PIBWDG_H      // Types enumeres repris de Peida:PIFontSize...
+#include PICMAP_H
+
+#include <list.h>
+
+
+/* 
+ *  Unique format actuellement gere : A4
+ *
+ */
+enum PIPaperSizes { PI_A3 = 0, PI_A4 = 1, PI_A5 = 2, PI_NotDef = -1};
+
+#define PAGE_WIDTH   21.0   /* == 595 points */
+#define PAGE_HEIGHT  29.7   /* == 842 points */
+
+#define PORTRAIT  1
+#define LANDSCAPE 0
+
+
+
+/* Valable pour une page, ou un bloc */
+typedef struct {
+    float X0;         /* Coordonnes sommet NO  */
+    float Y0;         /*  en unites courantes  */
+    float Tx;         /* Format                */
+    float Ty;         /*  en unites courantes  */
+    float Dx;         /* Coord sommet SE       */
+    float Dy;         /*  en unites courantes  */
+    int orientation;  /* LANDSCAPE OU PORTRAIT */
+} Format;
+
+
+typedef struct{
+    char *Name;
+    int  Tx;     /* En 1/72e de pouce  !!  */
+    int  Ty;     /* unite naturelle de ps  */
+} Media;
+
+
+
+
+class PSFile{
+
+public:
+
+		  PSFile (char * FileName, float Tx = 0, float Ty = 0,
+			  float Dx = 0, float Dy = 0);
+/*		  PSFile (PSFile *File, int PageNum, int BlocNum);*/
+/*		  PSFile (char * FileName, int PageNum, int BlocNum);*/
+
+    virtual      ~PSFile();
+
+    virtual int     IsEPS();
+    virtual char*   GetFileName();
+
+
+    /* A changer ?
+     * Pourrait introduire des incompatibilites
+     * en cas de chgt sur la struct format ?
+     */
+    virtual Format* GetFormat();
+
+    /*Attributs graphiques */
+    virtual PIColors    GetDrawColor();
+    virtual PIColors    GetFillColor();
+    virtual PIFontAtt   GetFontAtt();
+    virtual PIFontSize  GetFontSize();
+    virtual PILineAtt   GetLineAtt();
+    virtual PIMarker    GetMarker();
+
+    virtual void  NewPage(float Dx, float Dy, int orientation);
+    virtual void  EndPage();
+    virtual void  NewBloc(float x0, float y0, float Tx, float Ty,
+			  float Dx, float Dy);
+    virtual void  EndBloc();
+
+    /* Trace */
+    virtual void  DrawString  (float x,  float y, char *s, 
+			       PIColors DrawColor  = PI_NotDefColor, 
+			       PIFontAtt FontAtt   = PI_NotDefFontAtt, 
+			       int FontSize        = 8);
+    virtual void  DrawLine    (float x1, float y1, float x2, float y2, 
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawBox     (float x0, float y0, float Tx, float Ty, 
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawFBox    (float x0, float y0, float Tx, float Ty, 
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PIColors FillColor  = PI_NotDefColor, 
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawCircle  (float x0, float y0, float r, 
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawFCircle (float x0, float y0, float r,
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PIColors FillColor  = PI_NotDefColor, 
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawPolygon (float *x, float *y, int n,
+			       PIColors DrawColor  = PI_NotDefColor, 
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawFPolygon(float *x, float *y, int n,
+			       PIColors DrawColor  = PI_NotDefColor,
+			       PIColors FillColor  = PI_NotDefColor,
+			       PILineAtt LineAtt   = PI_NotDefLineAtt);
+    virtual void  DrawMarker  (float x0, float y0, 
+			       PIMarker MrkType    = PI_NotDefMarker, 
+			       PIColors DrawColor  = PI_NotDefColor);
+    virtual void  DrawMarkers (float *x0, float *y0, int n,
+			       PIMarker MrkType    = PI_NotDefMarker,
+			       PIColors DrawColor  = PI_NotDefColor); 
+
+    virtual void  Image(float x0, float y0, float Tx, float Ty,
+			int Nx, int Ny,
+			unsigned char *pict,
+			PIColorMap *mColorMap);
+
+
+
+
+
+
+private:
+
+    typedef struct {
+	off_t begin;
+	off_t end;
+    } Offset;
+    
+    /* Blocs */
+    typedef struct {
+	int    num;
+	char*  label;
+	Format format;
+	Offset offset;
+    } Bloc;
+    typedef list<Bloc> BlocList;  /* STL */
+
+    /* Pages */
+    typedef struct {
+	int num;
+	int BlocCounter;
+	Format format;
+	Offset offset;
+	BlocList mBlocList;       /* Page == Liste de blocs */
+    } Page;
+    typedef list<Page> PageList;  /* STL */
+
+
+    /* --> Toute la classe */
+    static PSFile** PSFiles;      /* Tableau des PSFiles existants */
+
+    /* --> le fichier */
+    FILE *   mPSFile;
+    char *   mPSFileName;
+    int      isEPS;               /* Vrai si PostScript Encapsule */
+    Format   mFormat;             /* Format par defaut */
+    int      PageCounter;         /* Nbre de pages */
+    PageList mPageList;           /* Fichier == Liste de pages */
+
+    /* Attributs graphiques */
+    enum PIColors    mDrawColor;  /* Couleur de trace courante */
+    enum PIColors    mFillColor;  /* Couleur de remplissage courante */
+    enum PIFontAtt   mFontAtt;
+    enum PIFontSize  mFontSize;
+    enum PILineAtt   mLineAtt;    /* Epaisseur d une ligne */
+    enum PIMarker    mMarker;     /* Marker courant */
+
+
+    /* Ecriture du PostScript dans le fichier Physique */
+    /* Le code se trouve ds PSDict.cc                  */
+    virtual void  WriteHeader();
+    virtual void  WriteTrailer();
+    virtual void  WriteNewPage(Page *mPage);
+    virtual void  WriteEndPage(Page *mPage);
+    virtual void  WriteNewBloc(Bloc *mBloc);
+    virtual void  WriteEndBloc(Bloc *mBloc);
+    virtual void  WriteDrawString(float x, float y, char* s);
+    virtual void  WriteDrawLine(float x1, float y1, float x2, float y2);
+    virtual void  WriteDrawBox(float x0, float y0, float Tx, float Ty);
+    virtual void  WriteDrawFBox(float x0, float y0, float Tx, float Ty);
+    virtual void  WriteDrawCircle(float x0, float y0, float r);
+    virtual void  WriteDrawFCircle(float x0, float y0, float r);
+    virtual void  WriteDrawPolygon(float *x, float *y, int n);
+    virtual void  WriteDrawFPolygon(float *x, float *y, int n);
+    virtual void  WriteDrawMarker(float x0, float y0);
+    virtual void  WriteDrawMarkers(float *x0, float *y0, int n);
+    virtual void  WriteImage(float x0, float y0, float Tx, float Ty,
+		     int Nx, int Ny, unsigned char *pict, PIColorMap *mColorMap);
+    virtual void  WriteSetColor(PIColors mDrawColor);
+    virtual void  WriteSetFont(PIFontAtt mFontAtt, int mFontSize);
+    virtual void  WriteSetLineWidth(PILineAtt mLineAtt);
+};  /* End class PSFile */
+
+#endif/* PSFILE_H_SEEN */
