Commit 8d19d171e599017f3f6b7158e4b01d40730096a0

Authored by Benjamin Renard
1 parent 78e89487

Fix bug with relative / mm margins definition

Fix bug with title size and color
Fix copyright position in page
Add file prefix definition
Give the possibility to run a request without parameters
Give the possibility to plot an empty page
config/DataBaseParameters/xsd/request/plot.xsd
... ... @@ -386,7 +386,8 @@
386 386 </xs:restriction>
387 387 </xs:simpleType>
388 388 </xs:element>
389   - <xs:element name="page" minOccurs="1" maxOccurs="1">
  389 + <xs:element name="filePrefix" type="xs:string" minOccurs="0" maxOccurs="1"/>
  390 + <xs:element name="page" minOccurs="0" maxOccurs="1">
390 391 <xs:complexType>
391 392 <xs:sequence>
392 393 <xs:element name="title" type="TitleType"
... ... @@ -455,7 +456,7 @@
455 456 type="xs:integer" />
456 457 </xs:complexType>
457 458 </xs:element>
458   - <xs:element name="panel" minOccurs="1"
  459 + <xs:element name="panel" minOccurs="0"
459 460 maxOccurs="unbounded">
460 461 <xs:complexType>
461 462 <xs:sequence>
... ... @@ -635,6 +636,7 @@
635 636 </xs:element>
636 637 <xs:element ref="PostProcessingElement" minOccurs="0" maxOccurs="1"/>
637 638 </xs:sequence>
  639 + <xs:attribute name="writeContextFile" type="xs:boolean"/>
638 640 </xs:complexType>
639 641 </xs:element>
640 642  
... ...
config/DataBaseParameters/xsd/request/request.xsd
... ... @@ -11,7 +11,7 @@
11 11 <xs:element name="params">
12 12 <xs:complexType>
13 13 <xs:sequence>
14   - <xs:element name="param" minOccurs="1" maxOccurs="unbounded">
  14 + <xs:element name="param" minOccurs="0" maxOccurs="unbounded">
15 15 <xs:complexType>
16 16 <xs:attribute name="id" type="xs:string" />
17 17 </xs:complexType>
... ...
src/ParamOutputImpl/Plot/CommonNode.cc
... ... @@ -21,14 +21,14 @@ void MarginNode::proceed(xmlNodePtr pNode,
21 21 // -- horizontal margin
22 22 value = xmlGetProp(pNode, (const xmlChar *) "x");
23 23 if (value) {
24   - element->_xMargin = atof((const char*) value);
  24 + element->calculateRelativeXMargin(element->_orientation, element->_dimension, atof((const char*) value));
25 25 xmlFree(value);
26 26 }
27 27  
28 28 // -- vertical margin
29 29 value = xmlGetProp(pNode, (const xmlChar *) "y");
30 30 if (value) {
31   - element->_yMargin = atof((const char*) value);
  31 + element->calculateRelativeYMargin(element->_orientation, element->_dimension, atof((const char*) value));
32 32 xmlFree(value);
33 33 }
34 34 }
... ...
src/ParamOutputImpl/Plot/Page.cc
... ... @@ -262,13 +262,22 @@ void Page::draw(std::shared_ptr&lt;plstream&gt;&amp; pls, bool newFile, const char *plotFi
262 262 // write title with dedicated position and align settings
263 263 pls->col0(0);
264 264  
  265 + Color lInitialColor = changeColor(pls, _title._color, _mode);
  266 +
265 267 // use page font if title font is not set
266 268 pls->sfont(getPlFontFamily(_title._font.isSet() ? _title._font : _font),
267   - getPlFontStyle(_title._style), getPlFontWeight(_title._style));
268   - pls->schr(getPlFontDef(_font), getPlFontScaleFactor(_font));
  269 + (_title._font.isSet() ? getPlFontStyle(_title._style) : _font._style),
  270 + (_title._font.isSet() ? getPlFontWeight(_title._style) : _font._weight));
  271 + if (_title._font.isSet())
  272 + pls->schr(getPlFontDef(_title._font), getPlFontScaleFactor(_title._font));
  273 + else
  274 + pls->schr(getPlFontDef(_font), getPlFontScaleFactor(_font));
269 275 pls->mtex(getPlSide(_titlePosition).c_str(), -1., getPlPos(_titleAlign),
270 276 getPlJust(_titleAlign), _title._text.c_str());
271 277  
  278 + // Restore initial color.
  279 + restoreColor(pls, lInitialColor, _mode);
  280 +
272 281 // write Created by AMDA(c) on bottom write
273 282 // write it on bottom right
274 283 // if HIDE_AMDA_DATE is not defined (used for fitnesse automatic image comparison)
... ... @@ -290,15 +299,26 @@ void Page::writeCopywrite(std::shared_ptr&lt;plstream&gt;&amp; pls) {
290 299 timeinfo = localtime(&rawtime);
291 300 strftime(buffer, 80, "%d/%m/%G %T", timeinfo);
292 301  
  302 + //set viewport
  303 + pls->vpor(0, 1, 0, 1);
  304 +
  305 + //use page font
  306 + std::vector<Label::Style> styles;
  307 + pls->sfont(getPlFontFamily(_font), getPlFontStyle(styles), getPlFontWeight(styles));
  308 + pls->schr(getPlFontDef(_font), getPlFontScaleFactor(_font));
  309 +
  310 +
293 311 // write text on right bottom of the page
294 312 pls->mtex("b", -1., 1, 1,
295 313 std::string(createdby + " v" + version + " " + std::string(buffer)).c_str());
296 314 }
297 315  
298 316 void Page::initPageParameters(std::shared_ptr<plstream>& pls) {
299   - // calculate default margin if not set
300   - calculateXMargin(_orientation, _dimension);
301   - calculateYMargin(_orientation, _dimension);
  317 + // get default margin if not set
  318 + if (_xMargin == -1)
  319 + _xMargin = DefaultPlotConfiguration::getInstance()._defaultPage._xMargin;
  320 + if (_yMargin == -1)
  321 + _yMargin = DefaultPlotConfiguration::getInstance()._defaultPage._yMargin;
302 322  
303 323 // set page size according to page format A4 or letter
304 324 // offset not seams to work
... ... @@ -322,12 +342,8 @@ void Page::initPageParameters(std::shared_ptr&lt;plstream&gt;&amp; pls) {
322 342 pls->setopt("dpi", dpi.str().c_str());
323 343 }
324 344  
325   -void Page::calculateXMargin(PlotCommon::Orientation& orientation,
326   - PlotCommon::Dimension& dimension) {
327   - if (_xMargin != -1) {
328   - return;
329   - }
330   -
  345 +void Page::calculateRelativeXMargin(PlotCommon::Orientation& orientation,
  346 + PlotCommon::Dimension& dimension, float xMarginInMm) {
331 347 float xlengthInMm;
332 348 switch (dimension) {
333 349 case PlotCommon::Dimension::US_letter:
... ... @@ -345,17 +361,11 @@ void Page::calculateXMargin(PlotCommon::Orientation&amp; orientation,
345 361 xlengthInMm = Page::A4_Y_LENGTH_IN_MM;
346 362 }
347 363 }
348   - // default xmargin in mm, return margin as relative coordinate
349   - _xMargin = DefaultPlotConfiguration::getInstance()._defaultPage._xMargin
350   - / xlengthInMm;
  364 + _xMargin = xMarginInMm / xlengthInMm;
351 365 }
352 366  
353   -void Page::calculateYMargin(PlotCommon::Orientation& orientation,
354   - PlotCommon::Dimension& dimension) {
355   - if (_yMargin != -1) {
356   - return;
357   - }
358   -
  367 +void Page::calculateRelativeYMargin(PlotCommon::Orientation& orientation,
  368 + PlotCommon::Dimension& dimension, float yMarginInMm) {
359 369 float ylengthInMm;
360 370 switch (dimension) {
361 371 case PlotCommon::Dimension::US_letter:
... ... @@ -373,9 +383,7 @@ void Page::calculateYMargin(PlotCommon::Orientation&amp; orientation,
373 383 ylengthInMm = Page::A4_X_LENGTH_IN_MM;
374 384 }
375 385 }
376   - // default xmargin in mm, return margin as relative coordinate
377   - _yMargin = DefaultPlotConfiguration::getInstance()._defaultPage._yMargin
378   - / ylengthInMm;
  386 + _yMargin = yMarginInMm / ylengthInMm;
379 387 }
380 388  
381 389 std::ostream& operator <<(std::ostream& out, Page& page) {
... ...
src/ParamOutputImpl/Plot/Page.hh
... ... @@ -166,17 +166,17 @@ public:
166 166 */
167 167 bool _superposeMode;
168 168  
  169 + void calculateRelativeXMargin(PlotCommon::Orientation& orientation,
  170 + PlotCommon::Dimension& dimension, float xMarginInMm);
  171 + void calculateRelativeYMargin(PlotCommon::Orientation& orientation,
  172 + PlotCommon::Dimension& dimension, float yMarginInMm);
  173 +
169 174 private:
170 175  
171 176 void initPageParameters(std::shared_ptr<plstream>& pls);
172 177  
173 178 void writeCopywrite(std::shared_ptr<plstream>& pls);
174 179  
175   - void calculateXMargin(PlotCommon::Orientation& orientation,
176   - PlotCommon::Dimension& dimension);
177   - void calculateYMargin(PlotCommon::Orientation& orientation,
178   - PlotCommon::Dimension& dimension);
179   -
180 180 };
181 181  
182 182 std::ostream& operator <<(std::ostream& out, Page& page);
... ...
src/ParamOutputImpl/Plot/PlotNode.cc
... ... @@ -19,6 +19,7 @@ namespace plot {
19 19 PlotNode::PlotNode() :
20 20 NodeGrpCfg() {
21 21 getChildList()["outputStructure"] = AMDA::XMLConfigurator::NodeCfgSPtr(new OutputStructureNode());
  22 + getChildList()["filePrefix"] = AMDA::XMLConfigurator::NodeCfgSPtr(new FilePrefixNode());
22 23 getChildList()["page"] = AMDA::XMLConfigurator::NodeCfgSPtr(new PageNode());
23 24 getChildList()["postProcess"] = AMDA::XMLConfigurator::NodeCfgSPtr(
24 25 new postprocessing::PostProcessingNode<PlotOutput>());
... ... @@ -55,4 +56,14 @@ void OutputStructureNode::proceed(xmlNodePtr pNode,
55 56 (const char*) pNode->children->content);
56 57 }
57 58  
  59 +void FilePrefixNode::proceed(xmlNodePtr pNode,
  60 + const AMDA::Parameters::CfgContext& pContext) {
  61 + LOG4CXX_DEBUG(gLogger, "FilePrefixNode::proceed")
  62 +
  63 + PlotOutput* lPlotOutput =
  64 + pContext.get<PlotOutput*>();
  65 + lPlotOutput->setFilePrefix(
  66 + (const char*) pNode->children->content);
  67 +}
  68 +
58 69 } /* namespace plot */
... ...
src/ParamOutputImpl/Plot/PlotNode.hh
... ... @@ -30,5 +30,16 @@ public:
30 30 const AMDA::Parameters::CfgContext& pContext);
31 31 };
32 32  
  33 +/**
  34 + * @class FilePrefixNode
  35 + * @brief read the "filePrefix" node.
  36 + */
  37 +class FilePrefixNode: public AMDA::XMLConfigurator::NodeCfg {
  38 +public:
  39 + void proceed(xmlNodePtr pNode,
  40 + const AMDA::Parameters::CfgContext& pContext);
  41 +};
  42 +
  43 +
33 44 } /* namespace plot */
34 45 #endif /* PLOTNODE_HH_ */
... ...
src/ParamOutputImpl/Plot/PlotOutput.cc
... ... @@ -17,7 +17,7 @@ namespace plot {
17 17  
18 18 PlotOutput::PlotOutput(AMDA::Parameters::ParameterManager& pParameterManager) :
19 19 AMDA::Parameters::VisitorOfParamData(), ParamOutput(pParameterManager),
20   - _currentParamId(""), _outputStructure(OutputStructure::ONE_FILE_PER_INTERVAL) {
  20 + _currentParamId(""), _outputStructure(OutputStructure::ONE_FILE_PER_INTERVAL), _filePrefix("plot") {
21 21  
22 22 }
23 23  
... ... @@ -151,9 +151,9 @@ void PlotOutput::initNewPage(int intervalIndex)
151 151 if ((_timeIntervalList->size() > 1) &&
152 152 (_outputStructure == OutputStructure::ONE_FILE_PER_INTERVAL) &&
153 153 !_page->_superposeMode)
154   - plotFilePrefix << "plot_" << intervalIndex << "_";
  154 + plotFilePrefix << _filePrefix << "_" << intervalIndex << "_";
155 155 else
156   - plotFilePrefix << "plot_";
  156 + plotFilePrefix << _filePrefix << "_";
157 157  
158 158 //draw page
159 159 _page->draw(_pls, newFile, plotFilePrefix.str().c_str());
... ...
src/ParamOutputImpl/Plot/PlotOutput.hh
... ... @@ -70,6 +70,15 @@ public:
70 70 }
71 71 }
72 72  
  73 + /**
  74 + * @brief sets the file prefix to use.
  75 + */
  76 + void setFilePrefix(const std::string& filePrefix)
  77 + {
  78 + LOG4CXX_DEBUG(gLogger,"PlotOutput::setFilePrefix " << filePrefix);
  79 + _filePrefix = filePrefix;
  80 + }
  81 +
73 82 AMDA::Parameters::ParameterManager& getParameterManager(){
74 83 return _parameterManager;
75 84 }
... ... @@ -270,6 +279,11 @@ private:
270 279 * Files to output, default is ONE_FILE_PER_INTERVAL
271 280 */
272 281 OutputStructure _outputStructure;
  282 +
  283 + /**
  284 + * File prefix to use
  285 + */
  286 + std::string _filePrefix;
273 287 };
274 288  
275 289 } /* namespace plot */
... ...