 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Thu Aug 01, 2013 7:28 pm Post subject: |
|
|
John-Silver,
I presume that all the dimensions and sizes are present in your original code. It is unlikely that you will find a package that employs the same data structures as you do, so you are probably down to drawing your objects yourself, including all the dimensioning information. You then have several choices:
(a) do it in FTN95/Clearwin's graphics onscreen, scaling to your screen area
(b) generate hardcopy using FTN95/Clearwin's graphics on a Windows installed printer (A4 cheap, A3 expensive, bigger than A3 VERY expensive)
(c) generate your pictures in an intermediate form, such as HPGL or AutoCAD DXF, import that file into (say) AutoCAD for 'embelishment' with title blocks, notes etc
(d) generate output using a plotter language such as HPGL, and plot directly to a pen plotter.
You will find several free DXF libraries in Fortran on the web.
Eddie |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sun Aug 04, 2013 2:41 pm Post subject: |
|
|
In which case do it yourself is my best advice. There are a lot of things you need to learn before it all comes together. My recommended route is to look in the documentation section of this site and download perhaps the Clearwin+ Fortran Edition document and read it: it is rather better than attempting to learn from the FTN95.CHM online help file.
Here is a compilable starter code:
Code: | WINAPP
OPTIONS (INTL, DREAL) ! sets INTEGER*4, REAL*8 as the default
PROGRAM TREASURE_ISLAND
C -----------------------
COMMON CORNERS(50,2), HOLES(10,3), NCORNERS, NHOLES
COMMON /VIEW/ IXRES, IYRES, iSCREEN, iPRINTER, KURRENT
INCLUDE <WINDOWS.INS>
INTEGER, EXTERNAL :: KALLBACK
CALL INITIALISE_SHAPE
CALL USE_RGB_COLOURS@(0,.TRUE.)
iSCREEN = 100; IXRES = 700; IYRES = 500
IA=WINIO@('%ca[Graphics test]&')
IA=WINIO@('%bg&', RGB@(230, 230, 255))
IA=WINIO@('%`gr[WHITE]&', IXRES, IYRES, iSCREEN)
IA=WINIO@('%ff%nl%rj%6^bt[Show] %6bt[Quit]', KALLBACK)
IF (IA .EQ. 0 .OR. IA .EQ. 2) STOP ! unnecessary in this example
END
SUBROUTINE INITIALISE_SHAPE
C ---------------------------
COMMON CORNERS(50,2), HOLES(10,3), NCORNERS, NHOLES
NHOLES = 3; NCORNERS = 5
HOLES(1,1) = 10.0; HOLES(1,2) = 10.0; HOLES(1,3) = 3.0
HOLES(2,1) = 30.0; HOLES(2,2) = 10.0; HOLES(2,3) = 5.0
HOLES(3,1) = 10.0; HOLES(3,2) = 30.0; HOLES(3,3) = 3.0
CORNERS(1,1) = 0.0; CORNERS(1,2) = 0.0
CORNERS(2,1) = 0.0; CORNERS(2,2) = 50.0
CORNERS(3,1) = 30.0; CORNERS(3,2) = 30.0
CORNERS(4,1) = 50.0; CORNERS(4,2) = 0.0
CORNERS(5,1) = 0.0; CORNERS(5,2) = 0.0
RETURN; END
SUBROUTINE DRAW_SHAPE
C ---------------------
COMMON CORNERS(50,2), HOLES(10,3), NCORNERS, NHOLES
COMMON /VIEW/ IXRES, IYRES, iSCREEN, iPRINTER, KURRENT
DIMENSION IX(50), IY(50)
INCLUDE <WINDOWS.INS>
C ... statement functions to 'inline' the mapping to the screen
IPOSX(XX) = (XX-CENTRE_X)/SCALE+IXRES/2
IPOSY(YY) = IYRES/2-(YY-CENTRE_Y)/SCALE
C ... find centre and scale factor to fit to graphics
XMIN = 0.0; XMAX = 0.0; YMIN = 0.0; YMAX = 0.0
DO 10 I=1,NCORNERS
XMIN = MIN (XMIN, CORNERS(I,1)); XMAX = MAX (XMAX, CORNERS(I,1))
YMIN = MIN (YMIN, CORNERS(I,2)); YMAX = MAX (YMAX, CORNERS(I,2))
10 CONTINUE
CENTRE_X = (XMIN+XMAX)/2.0; CENTRE_Y = (YMIN+YMAX)/2.0
SCALE = 1.1*MAX ((XMAX-XMIN)/IXRES, (YMAX-YMIN)/IYRES)
C ... Draw steel plate
DO 15 I=1, NCORNERS
IX(I) = IPOSX(CORNERS(I,1))
IY(I) = IPOSY(CORNERS(I,2))
15 CONTINUE
CALL DRAW_FILLED_POLYGON@ (IX, IY, NCORNERS, RGB@(192, 192, 192))
CALL DRAW_POLYLINE@ (IX, IY, NCORNERS, RGB@(0, 0, 0))
C ... Draw bolt holes
DO 20 I=1, NHOLES
JX = IPOSX(HOLES(I,1))
JY = IPOSY(HOLES(I,2))
JR = HOLES(I,3)/(2.0*SCALE)
CALL DRAW_FILLED_ELLIPSE@(JX, JY, JR, JR, RGB@(255,255,255))
CALL DRAW_ELLIPSE@(JX, JY, JR, JR, RGB@(0,0,0))
CALL DRAW_LINE_BETWEEN@(JX-3*JR/2, JY, JX+3*JR/2, JY, RGB@(0,0,0))
CALL DRAW_LINE_BETWEEN@(JX, JY-3*JR/2, JX, JY+3*JR/2, RGB@(0,0,0))
20 CONTINUE
C ... Draw dimension info
RETURN; END
|
Last edited by LitusSaxonicum on Tue Aug 06, 2013 1:36 pm; edited 2 times in total |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sun Aug 04, 2013 2:53 pm Post subject: |
|
|
Hi John-Silver,
Code: | INTEGER FUNCTION KALLBACK()
C ---------------------------
KALLBACK = 1
CALL DRAW_SHAPE
RETURN; END |
There is a maximum length per post, so here is the final routine and the explanation. I set up the program to be a Windows program (WINAPP), and to use INTEGER*4 and REAL*8 as defaults. Purists may not like implicit types, but they shorten the code. I used multiple statements per line using ; - and also you don't need RETURN these days. Somehow you have to get your coordinates - I have done this in a subroutine INITIALISE_SHAPE. You could read the coordinates from a file. I am going to draw a plate with 3 holes in it. The Window is set up to have a graphics area 700 pixels wide by 500 high on a coloured background. The graphics area is white. The window has a caption. Below the graphics area are 2 buttons labelled Show and Quit. We are going to use 24-bit colour (USE_RGB_COLOURS@).
When you click on the Show button, the plate is drawn. First of all there is a grey filled polygon, then it is outlined in black as a polyline. Then the holes are drawn, and the centre of each hole is indicated with a cross. The holes are drawn as white-filled ellipses, again outlined in black.
You could go on to draw dimension lines with DRAW_LINE_BETWEEN@ calls.
There are other graphics primitives for drawing text etc.
If this is the sort of thing you are after, I can go on to show you how to get precisely scaled output. In the example, I have scaled to fit within the screen area, and used two statement functions to provide the mapping from real-world coordinates to pixels. Statement functions are horrible, but they are short.
Eddie |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Tue Aug 06, 2013 10:15 am Post subject: |
|
|
John,
Getting it to draw automatically is a matter of getting the callback routine to operate on window startup. This is a matter of giving the format code "%sc", as follows:
Code: | IA=WINIO@('%sc&', KALLBACK) |
Now we know in the demo example that there are always CORNERS and HOLES data present, so that there is never a risk of attempting to calculate scales with no data (causing a divide by zero). However, if you do drawing on a %sc you will need to test for this. One way is to see how many corners and holes there are. However, there is a simpler way. You might try altering the code I posted to include %sc to see that it works. Then change the label on the Show button to Print, and instead of KALLBACK, give the callback routine a more sensible name - e.g. KB_PRINT or some such (it will need to be declared external, and a new FUNCTION provided.
I suggest too that you divide the existing KALLBACK routine into two parts:
a) a scaling part, and
b) a drawing part.
The point of this is that the drawing part is the same whether you are drawing on the screen or on a piece of paper, it is just the scaling that is different.
The scaling part is in effect just the line:
Code: | SCALE = 1.1*MAX ((XMAX-XMIN)/IXRES, (YMAX-YMIN)/IYRES) |
Where the scale is in mm/pixel or inch/pixel, and we have used 1.1 to make sure it fits in the space available with white space all round, and taken the MAX to cater for knowing whether the fit in x or in y is most critical.
To do hard copy, we need to know
I) if you want scale to fit, or an exact scale such as 1:500
II) what printer you expect to use
III) what the paper size and printer resolution is.
The only real difference between writing to the screen is changing the value of SCALE.
... on to post 2 |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Tue Aug 06, 2013 10:47 am Post subject: |
|
|
Most windows programs have a menu. My example does not. If you want a menu, you use WINIO@ with the format code %mn. This is dealt with at length in the documentation I pointed you to. Here is a fragment for a File menu
Code: | Menu_Grey = 0
IA=WINIO@('%mn[File[~Open,|,Print,|,Exit]]&', Menu_Grey,
& KB_File_Open, KB_File_Print, 'Exit') |
You would need to write callback routines KB_File_Open (to open a file of data), KB_File_Print (to print an image) but a standard callback 'EXIT' is provided to exit the program. File Open is also greyable, according to the value of Menu_Grey. If when you have successfully read a file, you set this value to 1, then Open will no longer be selectable. To test in the graphics routine whether or not you have data to plot it is only necessary to examine Menu_Grey! (Menu_Grey might be an array, looking after a lot of things that can be greyed out. IN this case you might be looking at Menu_Grey(1)).
If you have only one printer, and it is connected to your PC as the default printer, then you can use it for printing more simply than if you have multiple printers. If you make the call to OPEN_PRINTER@ with a handle you give it, like this:
Code: | iPrinter = 101
I = OPEN_PRINTER@ (iPrinter)
IF (I .EQ. 0) .... cater for the case where the user cancelled!
CALL GET_GRAPHICAL_RESOLUTION@ (IXRES, IYRES) |
Then you have all that you require to draw 'scaled to fit'. When you have finished printing a page. you can write
Code: | I = CLOSE_PRINTER@(iPrinter) |
or if you intend to make more copies, then
... on to post 3
Last edited by LitusSaxonicum on Tue Aug 06, 2013 1:35 pm; edited 1 time in total |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Tue Aug 06, 2013 11:41 am Post subject: |
|
|
To get precisely scaled output you need to know how many dots per inch (dpi) or dots per mm, and whether or not your plot will fit on the available paper. As well as the Clearwin+ routines, FTN95 has access to Windows own routines. One of these is GetDeviceCaps, and you need it to return you various parameters. GetDeviceCaps is not documented in FTN95's help file, but it (and many other things) is on MSDN. ("Caps" = "capabilities", "DC" = "device context").
Code: | CALL GET_CURRENT_DC@ (iPrinter)
CALL USE_RGB_COLOURS@(0,.true.) ! 0=use current drawing surface
C
C This is a printer. It would like to use colour indices 0..15. To
C force it to use RGB colours, we need the above call. Now it is
C the same as the screen. (Not obvious!!!!) .
C
ixdpi = GetDeviceCaps(iPrinter, LOGPIXELSX)
iydpi = GetDeviceCaps(iPrinter, LOGPIXELSY)
amm_wide = GetDeviceCaps(iPrinter, HORZSIZE)
amm_high = GetDeviceCaps(iPrinter, VERTSIZE)
IXRES = GetDeviceCaps(iPrinter, HORZRES)
IYRES = GetDeviceCaps(iPrinter, VERTRES) |
It doesn't normally help to set printer orientation to Portrait or Landscape because with merely sets a check box in the printer selection window, which the user can change. Here it is all the same:
Code: | CALL SET_PRINTER_ORIENTATION@ (0) Portrait
C (1) Landscape |
Scaling in then up to you. As the coordinates go left to right but top to bottom, you will find the statement functions I wrote for you still useful.
If you go on to print again to an already selected printer, you can use OPEN_PRINTER1@ - this also prints on the default printer if you haven't been through OPEN_PRINTER@.
As the Windows printer drivers simply ignore anything outside the printable areas, you don't need to clip any output. Simply set the position to map to the centre of each sheet and print again, making sure that you have an overlap. Do check that the scales are right though, otherwise you print hundreds of sheets with nothing on them!
Printer dpi tends to be 300, 600 or possibly 1200 for some makes of printer, but 360, 720 and 1440 for Epsons. If you get the finer settings, you will discover that 1 pixel lines get thin and faint, and you may need to adjust line thickness depending on dpi.
Some things I have noted are some printers giving slightly different paper sizes depending on whether they use US or other settings.
From now on you are on your own: read the documentation and experiment.
Best regards
Eddie |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|