PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plsdef.c
Go to the documentation of this file.
1 // Routines to set various plplot parameters, such as char height,
2 // symbol size, tick length, line and fill patterns, etc.
3 //
4 // Copyright (C) 2004-2014 Alan W. Irwin
5 //
6 // This file is part of PLplot.
7 //
8 // PLplot is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU Library General Public License as published
10 // by the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // PLplot is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public License
19 // along with PLplot; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 
23 #include "plplotP.h"
24 
25 // Line pattern defaults
26 
27 static struct line
28 {
30  PLINT mark[4];
32 } line[] = {
33  {
34  0, // Continuous line
35  {
36  0, 0, 0, 0
37  },
38  {
39  0, 0, 0, 0
40  }
41  },
42  {
43  1,
44  {
45  1000, 0, 0, 0
46  },
47  {
48  1000, 0, 0, 0
49  }
50  },
51  {
52  1,
53  {
54  2000, 0, 0, 0
55  },
56  {
57  2000, 0, 0, 0
58  }
59  },
60  {
61  1,
62  {
63  2000, 0, 0, 0
64  },
65  {
66  1000, 0, 0, 0
67  }
68  },
69  {
70  2,
71  {
72  2500, 1000, 0, 0
73  },
74  {
75  1000, 1000, 0, 0
76  }
77  },
78  {
79  2,
80  {
81  2000, 1000, 0, 0
82  },
83  {
84  2000, 1000, 0, 0
85  }
86  },
87  {
88  3,
89  {
90  1000, 1500, 2000, 0
91  },
92  {
93  1000, 1500, 2000, 0
94  }
95  },
96  {
97  3,
98  {
99  1000, 1500, 2000, 0
100  },
101  {
102  1000, 1000, 1000, 0
103  }
104  }
105 };
106 
107 // Fill pattern defaults
108 
109 static struct pattern
110 {
111  PLINT nlines; // Number of lines in pattern (1 or 2)
112  PLINT inc[2]; // Inclination 10 ths of degrees
113  PLINT del[2]; // Spacing for each line
114 } pattern[] = {
115  {
116  1,
117  {
118  0, 0
119  },
120  {
121  2000, 0
122  }
123  },
124  {
125  1,
126  {
127  900, 0
128  },
129  {
130  2000, 0
131  }
132  },
133  {
134  1,
135  {
136  450, 0
137  },
138  {
139  2000, 0
140  }
141  },
142  {
143  1,
144  {
145  -450, 0
146  },
147  {
148  2000, 0
149  }
150  },
151  {
152  1,
153  {
154  300, 0
155  },
156  {
157  2000, 0
158  }
159  },
160  {
161  1,
162  {
163  -300, 0
164  },
165  {
166  2000, 0
167  }
168  },
169  {
170  2,
171  {
172  0, 900
173  },
174  {
175  2000, 2000
176  }
177  },
178  {
179  2,
180  {
181  450, -450
182  },
183  {
184  2000, 2000
185  }
186  }
187 };
188 
189 // Set defining parameters for pattern fill
190 
191 static void
192 spat( const PLINT inc[], const PLINT del[], PLINT nlin );
193 
194 //--------------------------------------------------------------------------
195 // void plschr()
196 //
197 // Set character height.
198 //--------------------------------------------------------------------------
199 
200 void
201 c_plschr( PLFLT def, PLFLT scale )
202 {
203  if ( def != 0.0 )
204  plsc->chrdef = def;
205 
206  plsc->chrht = scale * plsc->chrdef;
207 }
208 
209 //--------------------------------------------------------------------------
210 // void plsmin()
211 //
212 // Set up lengths of minor tick marks.
213 //--------------------------------------------------------------------------
214 
215 void
216 c_plsmin( PLFLT def, PLFLT scale )
217 {
218  if ( def != 0.0 )
219  plsc->mindef = def;
220 
221  plsc->minht = scale * plsc->mindef;
222 }
223 
224 //--------------------------------------------------------------------------
225 // void plsmaj()
226 //
227 // Set up lengths of major tick marks.
228 //--------------------------------------------------------------------------
229 
230 void
231 c_plsmaj( PLFLT def, PLFLT scale )
232 {
233  if ( def != 0.0 )
234  plsc->majdef = def;
235 
236  plsc->majht = scale * plsc->majdef;
237 }
238 
239 //--------------------------------------------------------------------------
240 // void plssym()
241 //
242 // Set symbol height.
243 //--------------------------------------------------------------------------
244 
245 void
246 c_plssym( PLFLT def, PLFLT scale )
247 {
248  if ( def != 0.0 )
249  plsc->symdef = def;
250 
251  plsc->symht = scale * plsc->symdef;
252 }
253 
254 //--------------------------------------------------------------------------
255 // void pllsty()
256 //
257 // Set line style.
258 //--------------------------------------------------------------------------
259 
260 void
262 {
263  if ( plsc->level < 1 )
264  {
265  plabort( "pllsty: Please call plinit first" );
266  return;
267  }
268  if ( lin < 1 || lin > 8 )
269  {
270  plabort( "pllsty: Invalid line style" );
271  return;
272  }
273 
274  plsc->line_style = lin;
275  plstyl( line[lin - 1].nels,
276  &line[lin - 1].mark[0], &line[lin - 1].space[0] );
277 }
278 
279 //--------------------------------------------------------------------------
280 // void plpat()
281 //
282 // Set fill pattern directly.
283 //--------------------------------------------------------------------------
284 
285 void
286 c_plpat( PLINT nlin, const PLINT *inc, const PLINT *del )
287 {
288  PLINT i;
289 
290  if ( plsc->level < 1 )
291  {
292  plabort( "plpat: Please call plinit first" );
293  return;
294  }
295  if ( nlin < 1 || nlin > 2 )
296  {
297  plabort( "plpat: Only 1 or 2 line styles allowed" );
298  return;
299  }
300  for ( i = 0; i < nlin; i++ )
301  {
302  if ( del[i] < 0 )
303  {
304  plabort( "plpat: Line spacing must be greater than 0" );
305  return;
306  }
307  }
308  spat( inc, del, nlin );
309 }
310 
311 //--------------------------------------------------------------------------
312 // void plpsty()
313 //
314 // Set fill pattern, using one of the predefined patterns.
315 // A fill pattern <= 0 indicates hardware fill.
316 //--------------------------------------------------------------------------
317 
318 void
320 {
321  if ( plsc->level < 1 )
322  {
323  plabort( "plpsty: Please call plinit first" );
324  return;
325  }
326  if ( patt > 8 )
327  {
328  plabort( "plpsty: Invalid pattern" );
329  return;
330  }
331  if ( patt != plsc->patt )
332  {
333  plsc->patt = patt;
334 
335  if ( plsc->level > 0 )
336  {
338  }
339  }
340  if ( patt > 0 )
341  {
342  spat( &pattern[patt - 1].inc[0], &pattern[patt - 1].del[0],
343  pattern[patt - 1].nlines );
344  }
345 }
346 
347 //--------------------------------------------------------------------------
348 // void spat()
349 //
350 // Set defining parameters for pattern fill
351 //--------------------------------------------------------------------------
352 
353 static void
354 spat( const PLINT inc[], const PLINT del[], PLINT nlin )
355 {
356  PLINT i;
357 
358  plsc->nps = nlin;
359  for ( i = 0; i < nlin; i++ )
360  {
361  plsc->inclin[i] = inc[i];
362  plsc->delta[i] = del[i];
363  }
364 }