PLplot  5.11.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 #define NPATTERNS 8
110 static struct pattern
111 {
112  PLINT nlines; // Number of lines in pattern (1 or 2)
113  PLINT inc[2]; // Inclination 10 ths of degrees
114  PLINT del[2]; // Spacing for each line
115 } pattern[] = {
116  {
117  1,
118  {
119  0, 0
120  },
121  {
122  2000, 0
123  }
124  },
125  {
126  1,
127  {
128  900, 0
129  },
130  {
131  2000, 0
132  }
133  },
134  {
135  1,
136  {
137  450, 0
138  },
139  {
140  2000, 0
141  }
142  },
143  {
144  1,
145  {
146  -450, 0
147  },
148  {
149  2000, 0
150  }
151  },
152  {
153  1,
154  {
155  300, 0
156  },
157  {
158  2000, 0
159  }
160  },
161  {
162  1,
163  {
164  -300, 0
165  },
166  {
167  2000, 0
168  }
169  },
170  {
171  2,
172  {
173  0, 900
174  },
175  {
176  2000, 2000
177  }
178  },
179  {
180  2,
181  {
182  450, -450
183  },
184  {
185  2000, 2000
186  }
187  }
188 };
189 
190 // Set defining parameters for pattern fill
191 
192 static void
193 spat( const PLINT inc[], const PLINT del[], PLINT nlin );
194 
195 //--------------------------------------------------------------------------
196 // void plschr()
197 //
198 // Set character height.
199 //--------------------------------------------------------------------------
200 
201 void
202 c_plschr( PLFLT def, PLFLT scale )
203 {
204  if ( def != 0.0 )
205  plsc->chrdef = def;
206 
207  plsc->chrht = scale * plsc->chrdef;
208 
210 }
211 
212 //--------------------------------------------------------------------------
213 // void plsmin()
214 //
215 // Set up lengths of minor tick marks.
216 //--------------------------------------------------------------------------
217 
218 void
219 c_plsmin( PLFLT def, PLFLT scale )
220 {
221  if ( def != 0.0 )
222  plsc->mindef = def;
223 
224  plsc->minht = scale * plsc->mindef;
225 }
226 
227 //--------------------------------------------------------------------------
228 // void plsmaj()
229 //
230 // Set up lengths of major tick marks.
231 //--------------------------------------------------------------------------
232 
233 void
234 c_plsmaj( PLFLT def, PLFLT scale )
235 {
236  if ( def != 0.0 )
237  plsc->majdef = def;
238 
239  plsc->majht = scale * plsc->majdef;
240 }
241 
242 //--------------------------------------------------------------------------
243 // void plssym()
244 //
245 // Set symbol height.
246 //--------------------------------------------------------------------------
247 
248 void
249 c_plssym( PLFLT def, PLFLT scale )
250 {
251  if ( def != 0.0 )
252  plsc->symdef = def;
253 
254  plsc->symht = scale * plsc->symdef;
255 
257 }
258 
259 //--------------------------------------------------------------------------
260 // void pllsty()
261 //
262 // Set line style.
263 //--------------------------------------------------------------------------
264 
265 void
267 {
268  if ( plsc->level < 1 )
269  {
270  plabort( "pllsty: Please call plinit first" );
271  return;
272  }
273  if ( lin < 1 || lin > 8 )
274  {
275  plabort( "pllsty: Invalid line style" );
276  return;
277  }
278 
279  plsc->line_style = lin;
280  plstyl( line[lin - 1].nels,
281  &line[lin - 1].mark[0], &line[lin - 1].space[0] );
282 }
283 
284 //--------------------------------------------------------------------------
285 // void plpat()
286 //
287 // Set fill pattern directly.
288 //--------------------------------------------------------------------------
289 
290 void
291 c_plpat( PLINT nlin, const PLINT *inc, const PLINT *del )
292 {
293  PLINT i;
294 
295  if ( plsc->level < 1 )
296  {
297  plabort( "plpat: Please call plinit first" );
298  return;
299  }
300  if ( nlin < 1 || nlin > 2 )
301  {
302  plabort( "plpat: Only 1 or 2 line styles allowed" );
303  return;
304  }
305  for ( i = 0; i < nlin; i++ )
306  {
307  if ( del[i] < 0 )
308  {
309  plabort( "plpat: Line spacing must be greater than 0" );
310  return;
311  }
312  }
313  plsc->patt = NPATTERNS;
314  spat( inc, del, nlin );
315 }
316 
317 //--------------------------------------------------------------------------
318 // void plpsty()
319 //
320 // Set fill pattern, using one of the predefined patterns.
321 // A fill pattern <= 0 indicates hardware fill.
322 //--------------------------------------------------------------------------
323 
324 void
326 {
327  if ( plsc->level < 1 )
328  {
329  plabort( "plpsty: Please call plinit first" );
330  return;
331  }
332  if ( patt > NPATTERNS || patt < 0 )
333  {
334  plabort( "plpsty: Invalid pattern" );
335  return;
336  }
337  if ( patt != plsc->patt )
338  {
339  plsc->patt = patt;
340  }
341  if ( patt > 0 )
342  {
343  spat( &pattern[patt - 1].inc[0], &pattern[patt - 1].del[0],
344  pattern[patt - 1].nlines );
345  }
346  else
347  spat( NULL, NULL, 0 );
348 }
349 
350 //--------------------------------------------------------------------------
351 // void spat()
352 //
353 // Set defining parameters for pattern fill
354 //--------------------------------------------------------------------------
355 
356 static void
357 spat( const PLINT inc[], const PLINT del[], PLINT nlin )
358 {
359  PLINT i;
360 
361  plsc->nps = nlin;
362  for ( i = 0; i < nlin; i++ )
363  {
364  plsc->inclin[i] = inc[i];
365  plsc->delta[i] = del[i];
366  }
367 
369 }