View HPGL Plotfile
1 Create this program step by step with Visualc++.net or VisualC++ 6.0

The content in the file are a lot of coordinates (x and y).
You only have to evaluate it. How? You can do step by step
with the instructions on the left side...

The HPGL File you can download on this link:
Download the HPGL Plotfile (16,0 Kbyte)
  • Start Visual C++.net or Visual C++6.0
  • Create new project MFC named HPGL Plotfile and choose SDI(Single Document)
    without data bank support and activeX, Maximized.


  • open the file View HPGL PlotfileDoc.cpp

  • insert the variable iFilesize and cBuffer

  • info: these are global variables
    // View HPGL PlotfileDoc.cpp : implementation of the CViewHPGLPlotfileDoc class
    #include "stdafx.h"
    #include "View HPGL Plotfile.h"
    
    #include "View HPGL PlotfileDoc.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    char cBuffer[1000000];  //	big memory for the whole HPGL File
    int nFileSize;		// 	the lenght of the file
    
    
    
  • now insert the code in function: Serialize

  • insert only this line: iFileSize = ar.Read(cBuffer,100000);
    void CosciDoc::Serialize(CArchive& ar)
    {
    	if (ar.IsStoring())
    	{
    		// TODO: add storing code here
    	}
    	else
    	{
    		// TODO: add loading code here
    		nFileSize = ar.Read(cBuffer,100000);	//here you have to insert the line
    							//with this line the program read the file
    	}
    }
    
    
  • Have you tested the program ? Everthing okay?

  • In the file "ViewHPGLPlotfileView.cpp" we declare the same variables as in "View HPGL PlotfileDoc.cpp", but as extern

  • we need some more variables.
    // View HPGL PlotfileView.cpp : implementation of the CViewHPGLPlotfileView class
    
    #include "stdafx.h"
    #include "View HPGL Plotfile.h"
    
    #include "View HPGL PlotfileDoc.h"
    #include "View HPGL PlotfileView.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    extern char cBuffer[1000000];  	// big memory from View HPGL PlotfileDoc.cpp declared as extern
    extern int nFileSize;		//the lenght of the file from View HPGL PlotfileDoc.cpp declared as extern
    char *ptr1,*ptr1end;		//pointers who read the lenght of the file
    char cLine[100];         	//little memory to scan only pieces from the file
    char *ptr2;			//pointer who takes the values into the little memory
    int penx = 0;           	//you need this one at the end for draw
    int xx, yy, aa, bb;		//variables for draw
    
    
  • Open file View HPGL PlotfileView.cpp and search:
  • void CViewHPGLPlotfileView::OnDraw(CDC* /*pDC*/)
  • Change this line into:
  • void CViewHPGLPlotfileView::OnDraw(CDC* pDC)

    
    
  • Have you tested the program ? Everthing okay?

  • Show that the file is loaded

  • Go to the View HPGL PlotfileView.cpp and down to

  • void CViewHPGLPlotfileView::OnDraw(CDC* pDC)

    if(nFileSize==0) return;
    CString str1;
    str1.Format("File open %d %X", nFileSize, nFileSize);
    pDC->TextOut(300,50,str1);

    //Here you have to write the evaluation(point 8)

    pDC->TextOut(300,50,"File loaded");
  • Set the pointer

  • write this lines into the position at point 7
    
    ptr1       = &cBuffer[0];
    ptr1end   = ptr1 + nFileSize;      //Pointer are set
    
  • evaluate from the HPGL-File

  • write this lines after you have set the pointers
    
    while(ptr1 < ptr1end)			
    	 {
         ptr2 = &cLine[0];   			// ptr2 on top of the small memory 
             
    	while(*ptr1 != ';') *ptr2++ = *ptr1++;	// while the volume (the byte) irregular; while ptr1 unequal ";" load the adress from ptr2
    	   					// a plus at the end increments the pointer  
    	{
    	    ptr1++;   				// jump over the semicolon
           
    	// ====files are in the small memory====
    	   
    	   *ptr2=NULL;  //mark off the files
               
    		if(cLine[0]=='P')           	// evaluation only when the first letter is a 'P'
    		{
    		if(cLine[1]== 'U') penx = 0; 	//if the first letter is an 'U' pen x = 0 (move to)
    		if(cLine[1]== 'D') penx = 1;	//if the first letter is an 'D' pen x = 1 (line to)
    		if(cLine[1]== 'A')		//if the first letter is an 'A' the linescan can begin
    		{
    		sscanf(cLine,"PA%d,%d", &aa, &bb);  aa/=20;  bb/=20;//scan the line(line,"how exactly looks the line",make aa & bb looks like the coordinats)   
    		xx=800-aa;			//move the picture in x-direction
    		yy=600-bb;			//move the picture in y-direction
    		if(penx == 0) pDC->MoveTo(xx,yy);//move to the coordinats xx,yy only when penx=0			 
    		         else pDC->LineTo(xx,yy);//line to the coordinats xx,yy only when penx=!
                  
    		}//end when 'A'
    	   	}//end when first letter = 'P'  
    		}// End of ptr1
    	 	}
    
    
    
  • View HPGL PlotfileDoc.cpp:
  • // View HPGL PlotfileDoc.cpp : implementation of the CViewHPGLPlotfileDoc class
    //
    
    #include "stdafx.h"
    #include "View HPGL Plotfile.h"
    
    #include "View HPGL PlotfileDoc.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    
    extern char cBuffer[];  //	grosse Speicher
    extern int nFileSize;
    
    
    // CViewHPGLPlotfileDoc
    
    IMPLEMENT_DYNCREATE(CViewHPGLPlotfileDoc, CDocument)
    
    BEGIN_MESSAGE_MAP(CViewHPGLPlotfileDoc, CDocument)
    END_MESSAGE_MAP()
    
    
    // CViewHPGLPlotfileDoc construction/destruction
    
    CViewHPGLPlotfileDoc::CViewHPGLPlotfileDoc()
    {
    	// TODO: add one-time construction code here
    
    }
    
    CViewHPGLPlotfileDoc::~CViewHPGLPlotfileDoc()
    {
    }
    
    BOOL CViewHPGLPlotfileDoc::OnNewDocument()
    {
    	if (!CDocument::OnNewDocument())
    		return FALSE;
    
    	// TODO: add reinitialization code here
    	// (SDI documents will reuse this document)
    
    	return TRUE;
    }
    
    
    
    
    // CViewHPGLPlotfileDoc serialization
    
    void CViewHPGLPlotfileDoc::Serialize(CArchive& ar)
    {
    	if (ar.IsStoring())
    	{
    		// TODO: add storing code here
    	}
    	else
    	{
    	
    		nFileSize = ar.Read(cBuffer,5000000);
    		// TODO: add loading code here
    	}
    }
    
    
    // CViewHPGLPlotfileDoc diagnostics
    
    #ifdef _DEBUG
    void CViewHPGLPlotfileDoc::AssertValid() const
    {
    	CDocument::AssertValid();
    }
    
    void CViewHPGLPlotfileDoc::Dump(CDumpContext& dc) const
    {
    	CDocument::Dump(dc);
    }
    #endif //_DEBUG
    
    
    // CViewHPGLPlotfileDoc commands
    

  • View HPGL PlotfileView.cpp:
  • // View HPGL PlotfileView.cpp : implementation of the CViewHPGLPlotfileView class // #include "stdafx.h" #include "View HPGL Plotfile.h" #include "View HPGL PlotfileDoc.h" #include "View HPGL PlotfileView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif char cBuffer[100000000]; // grosse Speicher int nFileSize; char *ptr1; char *ptr1ende; int stiftx = 0; //0= Stift oben 1= Stift unten char cZeile[100]; //kleine Speicher char *ptr2; int xx, yy, aa, bb; // CViewHPGLPlotfileView IMPLEMENT_DYNCREATE(CViewHPGLPlotfileView, CView) BEGIN_MESSAGE_MAP(CViewHPGLPlotfileView, CView) END_MESSAGE_MAP() // CViewHPGLPlotfileView construction/destruction CViewHPGLPlotfileView::CViewHPGLPlotfileView() { // TODO: add construction code here } CViewHPGLPlotfileView::~CViewHPGLPlotfileView() { } BOOL CViewHPGLPlotfileView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // CViewHPGLPlotfileView drawing void CViewHPGLPlotfileView::OnDraw(CDC* pDC) // pointer freimachen { CViewHPGLPlotfileDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // Anzeigen dass Datei geladen ist! if(nFileSize==0) return; CString str1; str1.Format("File open %d %X", nFileSize, nFileSize); pDC->TextOut(800,75,str1); // scan in the buffer ptr1 = &cBuffer[0]; ptr1ende = ptr1 + nFileSize; //Pointer are set while(ptr1 < ptr1ende) { ptr2 = &cZeile[0]; // ptr2 on top of the small memory while(*ptr1 != ';') *ptr2++ = *ptr1++; { // while the volume (the byte) irregular Solange der Inhalt (das Byte) wo ptr1 hinzeigt ungleich dem Strichpunkt // lade in die Adresse wo ptr2 hinzeigt, den Inhalt von wo ptr1 hinzeigt // PlusPlus am Ende erhöht die Zeiger ptr1++; // Den Strich überspringen // ====Daten sind im kleinem Speicher==== *ptr2=NULL; //Daten abgrenzen if(cZeile[0]=='P') // Auswertung nur wenn der erste Buchstabe ein 'P' ist { if(cZeile[1]== 'U') stiftx = 0; if(cZeile[1]== 'D') stiftx = 1; if(cZeile[1]== 'A') { sscanf(cZeile,"PA%d,%d", &aa, &bb); aa/=20; bb/=20; xx=800-aa; yy=600-bb; if(stiftx == 0) pDC->MoveTo(xx,yy); else pDC->LineTo(xx,yy); }// Ende wenn 'A' }//Ende wenn erster Buchstabe 'P' } // End of ptr1 } pDC->TextOut(800,100,"File loaded"); } // CViewHPGLPlotfileView diagnostics #ifdef _DEBUG void CViewHPGLPlotfileView::AssertValid() const { CView::AssertValid(); } void CViewHPGLPlotfileView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CViewHPGLPlotfileDoc* CViewHPGLPlotfileView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewHPGLPlotfileDoc))); return (CViewHPGLPlotfileDoc*)m_pDocument; } #endif //_DEBUG // CViewHPGLPlotfileView message handlers