0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / PlotMgt / PlotMgt_PlotterTools.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <Standard_Type.hxx>
19#include <OSD_Path.hxx>
20#include <OSD_File.hxx>
21#include <PlotMgt_PlotterTools.hxx>
22
23//==============================================================================
24ParameterDesc __PossibleParameters [] = {
25 { PLOT_CONFIGVER, NULL, _T_STR, 0 },
26 { PLOT_MODEL, "PLOTPAR", _T_STR, 0 },
27 { PLOT_TITLE, "PLOTTIT", _T_STR, 0 },
28 { PLOT_EXTENSION, "PLOTUNI", _T_STR, 0 },
29 { PLOT_BACKDRAW, NULL, _T_STR, 0 },
30 { PLOT_COMMENTS, NULL, _T_STR, 0 },
31 { PLOT_COLORMAPRGB, NULL, _T_STR, 1 },
32 { PLOT_LINETYPEMAP, NULL, _T_STR, 1 },
33 { PLOT_FONTMAP, NULL, _T_STR, 1 },
34 { PLOT_BEFORECMD, NULL, _T_STR, 0 },
35 { PLOT_AFTERCMD, NULL, _T_STR, 0 },
36 { PLOT_PRINTCMD, NULL, _T_STR, 0 },
37
38 { PLOT_DIALOGUNIT, NULL, _T_LSTR, 0 },
39 { PLOT_OUTFORMAT, "PLOTFMT", _T_LSTR, 0 },
40 { PLOT_IMGFORMAT, "IMAGFMT", _T_LSTR, 0 },
41 { PLOT_DRVTYPE, "PLOTDRV", _T_LSTR, 0 },
42 { PLOT_PAPERFORMAT, NULL, _T_LSTR, 0 },
43 { PLOT_ORIENTATION, NULL, _T_LSTR, 0 },
44 { PLOT_QUALITY, NULL, _T_LSTR, 0 },
45 { PLOT_PAPERFEED, NULL, _T_LSTR, 0 },
46 { PLOT_ORIGIN, "PLOTORI", _T_LSTR, 0 },
47 { PLOT_COLORMAPPING, NULL, _T_LSTR, 0 },
48 { PLOT_PLOTTINGTYPE, "PLOTTYP", _T_LSTR, 0 },
49 { PLOT_ROTATION, NULL, _T_LSTR, 0 },
50
51 { PLOT_SETBKWHITE, NULL, _T_BOOL, 0 },
52 { PLOT_MIRRORDRIVEN, NULL, _T_BOOL, 0 },
53 { PLOT_MIRRORING, NULL, _T_BOOL, 0 },
54 { PLOT_QUALITYDRIVEN, NULL, _T_BOOL, 0 },
55 { PLOT_COPYDRIVEN, NULL, _T_BOOL, 0 },
56 { PLOT_FEEDDRIVEN, "PLOTAUT", _T_BOOL, 0 },
57 { PLOT_CUTDRIVEN, "PLOTCUT", _T_BOOL, 0 },
58 { PLOT_PLOTTINGCOLOR, NULL, _T_BOOL, 0 },
59 { PLOT_PLOTTERCOLOR, "PLOTCOL", _T_BOOL, 0 },
60 { PLOT_CIRCLEDRIVEN, "PLOTCIR", _T_BOOL, 0 },
61 { PLOT_ELLIPSEDRIVEN, "PLOTELL", _T_BOOL, 0 },
62 { PLOT_CURVEDRIVEN, "PLOTCUR", _T_BOOL, 0 },
63 { PLOT_TEXTDRIVEN, "PLOTTEX", _T_BOOL, 0 },
64 { PLOT_MARKERDRIVEN, NULL, _T_BOOL, 0 },
65 { PLOT_RECTANGLEDRIVEN, NULL, _T_BOOL, 0 },
66 { PLOT_FILLDRIVEN, NULL, _T_BOOL, 0 },
67 { PLOT_CHECKSUMDRIVEN, "PLOTCHK", _T_BOOL, 0 },
68 { PLOT_MEDIASAVDRIVEN, NULL, _T_BOOL, 0 },
69 { PLOT_ENDOFPLOTDRIVEN, NULL, _T_BOOL, 0 },
70 { PLOT_DRYTIMEDRIVEN, NULL, _T_BOOL, 0 },
71 { PLOT_ROTATEDRIVEN, NULL, _T_BOOL, 0 },
72 { PLOT_FRAME, NULL, _T_BOOL, 0 },
73 { PLOT_FRAMEAROUNDIMG, NULL, _T_BOOL, 0 },
74 { PLOT_MULTISHEET, NULL, _T_BOOL, 0 },
75 { PLOT_PLOTCOMMENT, NULL, _T_BOOL, 0 },
76 { PLOT_PLOTTITLE, NULL, _T_BOOL, 0 },
77 { PLOT_PLOTBACKDRAW, NULL, _T_BOOL, 0 },
78
79 { PLOT_MINLEFTMARGIN, NULL, _T_REAL, 0 },
80 { PLOT_MINBOTTOMMARGIN, NULL, _T_REAL, 0 },
81 { PLOT_MINTOPMARGIN, NULL, _T_REAL, 0 },
82 { PLOT_MINRIGHTMARGIN, NULL, _T_REAL, 0 },
83 { PLOT_LEFTMARGIN, "PLOTDEX", _T_REAL, 0 },
84 { PLOT_BOTTOMMARGIN, "PLOTDEY", _T_REAL, 0 },
85 { PLOT_TOPMARGIN, NULL, _T_REAL, 0 },
86 { PLOT_RIGHTMARGIN, NULL, _T_REAL, 0 },
87 { PLOT_WIDTHOFFSET, NULL, _T_REAL, 0 },
88 { PLOT_WIDTHSCALE, NULL, _T_REAL, 0 },
89 { PLOT_LENGTHOFFSET, NULL, _T_REAL, 0 },
90 { PLOT_LENGTHSCALE, NULL, _T_REAL, 0 },
91 { PLOT_PLOTTINGGAP, "PLOTDIF", _T_REAL, 0 },
92 { PLOT_WIDTHMAP, NULL, _T_REAL, 1 },
93 { PLOT_WIDTHMAXGAP, NULL, _T_REAL, 0 },
94 { PLOT_LINETYPEMAXGAP, NULL, _T_REAL, 0 },
95 { PLOT_RESOLUTION, "PLOTRES", _T_REAL, 0 },
96 { PLOT_COLORRESOLUTION, NULL, _T_REAL, 0 },
97 { PLOT_PHYSICALSTEP, NULL, _T_REAL, 0 },
98 { PLOT_MINWIDTHOFLINE, NULL, _T_REAL, 0 },
99 { PLOT_PAPERWIDTH, "PLOTWID", _T_REAL, 0 },
100 { PLOT_PAPERLENGTH, "PLOTLEN", _T_REAL, 0 },
101 { PLOT_FILLWIDTH, NULL, _T_REAL, 0 },
102
103 { PLOT_MAXCOLORS, NULL, _T_INT, 0 },
104 { PLOT_MAXPATTERMS, NULL, _T_INT, 0 },
105 { PLOT_COLORMAXGAP, NULL, _T_INT, 0 },
106 { PLOT_STYLUSNUMBER, "PLOTSTY", _T_INT, 0 },
107 { PLOT_DENSITY, "PLOTNIB", _T_INT, 0 },
108 { PLOT_MAXPENS, "PLOTMXP", _T_INT, 0 },
109 { PLOT_MOUNTEDPENS, "PLOTNBP", _T_INT, 0 },
110 { PLOT_PENSINDEXWIDTH, NULL, _T_INT, 1 },
111 { PLOT_PENSINDEXCOLOR, NULL, _T_INT, 1 },
112 { PLOT_PENSINDEXTYPE, NULL, _T_INT, 1 },
113 { PLOT_MEDIASAVTIME, NULL, _T_INT, 0 },
114 { PLOT_ENDOFPLOTTIMER, NULL, _T_INT, 0 },
115 { PLOT_DRYTIME, NULL, _T_INT, 0 },
116 { PLOT_COPIES, NULL, _T_INT, 0 },
117
118 { NULL, NULL, _T_UNK, 0 }
119};
120
121//==============================================================================
122static TCollection_AsciiString anErrorMsg;
123
124//==============================================================================
125Standard_CString PARAM_BAD_VALUE1 (const Standard_CString aMethodName) {
126 anErrorMsg = "PlotMgt_Plotter::SetParameter (must be > 0) from ";
127 anErrorMsg += aMethodName;
128 anErrorMsg += " ()";
129 return anErrorMsg.ToCString ();
130}
131
132//==============================================================================
133Standard_CString PARAM_BAD_VALUE2 (const Standard_CString aMethodName) {
134 anErrorMsg = "PlotMgt_Plotter::SetParameter (must be -1 or 0) from ";
135 anErrorMsg += aMethodName;
136 anErrorMsg += " ()";
137 return anErrorMsg.ToCString ();
138}
139
140//==============================================================================
141char* trim (char* buffer)
142{
143 char *first=NULL, *last=NULL;
144 first = strchr ( buffer, ':' ) + 1;
145 while ( *first == ' ' ) first++;
146 last = first + strlen(first) - 1;
147 if ( *last == '\n' ) { last--; *(last+1) = '\0'; }
148 while ( *last == ' ' ) { last--; *(last+1) = '\0'; }
149 return first;
150}
151
152//==============================================================================
153// Finds item <anItem> in the sequence <aList> and returns <index> if item
154// exists in the list. Otherwise returns 0.
155//==============================================================================
156Standard_Integer ItemIndex (Handle(TColStd_HSequenceOfAsciiString)& aList,
157 const TCollection_AsciiString& anItem,
158 const Standard_Integer nStartIndex)
159{
160 if (aList.IsNull())
161 return 0;
162 Standard_Integer i, theLength = aList->Length ();
163 if ((nStartIndex < 1) || (nStartIndex > theLength))
164 return 0;
165 for (i = nStartIndex; i <= theLength; i++)
166 if ( anItem.IsEqual(aList->Value(i).ToCString()) )
167 return i;
168 return 0;
169}
170
171//==============================================================================
172// Fill the list <aList> by using file iterator <anIterator>
173//==============================================================================
174#define SORT_LIST
175void FillListByIterator (Handle(TColStd_HSequenceOfAsciiString)& aList,
176 OSD_FileIterator& anIterator,
177 Standard_CString aNeedExtension,
178 // If plotter already exist in the list do not use it.
179 const Standard_Boolean aCheckExisted)
180{
181 Standard_Boolean anAddInList;
182 OSD_File aFile;
183 OSD_Path aPath;
184 TCollection_AsciiString aName;
185 while (anIterator.More ()) {
186 aFile = anIterator.Values ();
187 aFile.Path (aPath);
188 aName = aPath.Name ();
189 anAddInList = ( !aCheckExisted ||
190 (aCheckExisted && !ItemIndex(aList, aName)) );
191 if (aNeedExtension!=NULL)
192 anAddInList = (anAddInList && (aPath.Extension() == aNeedExtension));
193 anAddInList = (anAddInList && !aName.IsEmpty());
194 if (anAddInList)
195#ifdef SORT_LIST
196 {
197 Standard_Integer i = 1, n = aList->Length();
198 if (n != 0) {
199 while ( i < n && (aList->Value(i) < aName) ) i++;
200 if (i == n) aList->Append(aName);
201 else aList->InsertBefore(i, aName);
202 } else aList->Append(aName);
203 }
204#else
205 aList->Append(aName);
206#endif
207 anIterator.Next();
208 }
209}
210#undef SORT_LIST