NCBI C++ ToolKit
svg_grabber.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Vladislav Evgeniev
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 #include <gui/opengl/glresmgr.hpp>
37 
38 #include <util/image/image.hpp>
39 
40 #include <corelib/ncbifile.hpp>
41 
43 
45  : m_Pane(pane)
46  , m_OutputStream(NULL)
47 {
48 }
49 
50 
52 {
53  if (ostr) {
54  m_OutputStream = ostr;
55  }
56 }
57 
60 {
61  if (progress != NULL)
62  progress->SetGLContext();
63 
64  x_BeginCaptures(tex_size);
65 
68 
69  unique_ptr<CNcbiOstream> pstrm;
70  if ( !m_OutputStream ) {
71  string pdfname = CDir::ConcatPath(m_Directory, m_BaseImageName + "." + m_ImageFormat);
72  pstrm.reset(new CNcbiOfstream(pdfname.c_str(), ios::out | ios::binary));
73  m_OutputStream = pstrm.get();
74  }
75 
76  const TVPRect& viewport = m_Pane.GetViewportRect();
77  // Set the size of the rendered area (full viewport)
78  CMedia m("",
79  viewport.Width(),
80  viewport.Height() + m_TitleHeight,
82 
83  // to have margins we have to pass in a viewport that fits within them
84  // (e.g. 20,20,20,20 = vp(20, 20, width-40, height-40) but for now
85  // we are using the screens viewport size only
86  m_PrintOptions->SetMarginBottom(0);
87  m_PrintOptions->SetMarginLeft(0);
88  m_PrintOptions->SetMarginRight(0);
89  m_PrintOptions->SetMarginTop(0);
90 
91  m_PrintOptions->SetMedia(m);
92 
93  m_PrintOptions->DisableGouraudShading(m_DisableGouraudShaded);
94 
95 
96  //***************************************************
97 
98  if (m_TitleHeight>0.0f)
99  m_Pane.AddTitle(true);
100 
102  m_SVGRenderer->Initialize(TVPRect(viewport.Left(), viewport.Bottom(), viewport.Right(), viewport.Top() + m_TitleHeight));
103  m_SVGRenderer->SetSimplified(m_PrintOptions->GetGouraudShadingDisabled());
104 
105  m_Pane.RenderVectorGraphics((int)m_PrintOptions->GetMedia().GetWidth(), (int)m_PrintOptions->GetMedia().GetHeight());
106 
108 
110  m_PrintOptions.release();
111 
112  return eSuccess;
113 }
114 
115 void CSVGGrabber::x_BeginCaptures(int /*buffer_size*/)
116 {
117  m_ModelViewScaler = 1.0f;
118  m_GuideWidthX = 0;
119  m_GuideWidthY = 0;
120 
121 
122  m_PrintOptions.reset(new CPrintOptions());
123 
124  m_PrintOptions->SetPageOrientation(CPrintOptions::ePortrait);
126  m_PrintOptions->SetFilename(fname.c_str());
127  m_PrintOptions->SetMarginBottom(20);
128  m_PrintOptions->SetMarginLeft(20);
129  m_PrintOptions->SetMarginRight(20);
130  m_PrintOptions->SetMarginTop(20);
131  m_PrintOptions->SetPagesWide(1);
132  m_PrintOptions->SetPagesTall(1);
133 
134  m_PrintOptions->SetOutputFormat(CPrintOptions::eSvg);
135 }
136 
138 {
139 }
140 
142 {
144  if (mgr.IsNull()) {
145  mgr.Reset(new CSVGRenderer());
147  }
148  CSVGRenderer* svg = dynamic_cast<CSVGRenderer*>(mgr.GetPointerOrNull());
149  _ASSERT(svg);
150  m_SVGRenderer.Reset(svg);
153 }
154 
virtual void ResetState()
void SetOutputStream(CNcbiOstream *ostr)
Definition: svg_grabber.cpp:51
unique_ptr< CPrintOptions > m_PrintOptions
Definition: svg_grabber.hpp:90
IVectorGraphicsRenderer & m_Pane
Pane display canvas for the tree we are saving.
Definition: svg_grabber.hpp:76
CRef< CSVGRenderer > m_SVGRenderer
Definition: svg_grabber.hpp:91
void x_EndCaptures()
Called to restore values (in pane) when capturing stops.
virtual eCaptureResult GrabImages(int tex_size, IImageGrabberProgress *p=NULL)
Grab the requested images.
Definition: svg_grabber.cpp:59
CSVGGrabber(IVectorGraphicsRenderer &pane)
Definition: svg_grabber.cpp:44
CNcbiOstream * m_OutputStream
Definition: svg_grabber.hpp:88
void x_BeginCaptures(int buffer_size)
Called to setup values before image capturing starts.
CVect2< float > m_ModelViewScaler
Ratio scalers for the drawing area that maps to the images.
Definition: svg_grabber.hpp:86
void x_InitRenderer()
Instantiates the PDF renderer.
@ ePdfUnit
Definition: print_utils.hpp:52
virtual void SetGLContext()
std::string m_BaseImageName
Image name without its appended number (e.g. img for img1, img2...)
TModelUnit m_TitleHeight
Allow space at the top for a title.
std::string m_Directory
Target directory for saved images.
std::string m_ImageFormat
Image output format (e.g. jpeg, png...)
int m_GuideWidthX
If we are making space for printing guides (margins) on the sides, those margins may have different s...
bool m_DisableGouraudShaded
If true, disable gouraud-shaded polys (shadingtype 4)
Interface class for the pdf renderer.
virtual const TVPRect & GetViewportRect() const =0
virtual void RenderVectorGraphics(int vp_width, int vp_height)=0
virtual void UpdateVectorLayout()=0
virtual void AddTitle(bool b)=0
std::ofstream out("events_result.xml")
main entry point for tests
#define NULL
Definition: ncbistd.hpp:225
static string ConcatPath(const string &first, const string &second)
Concatenate two parts of the path for the current OS.
Definition: ncbifile.cpp:776
static CGlResMgr & Instance()
Definition: glresmgr.cpp:59
T Height() const
Definition: glrect.hpp:90
CIRef< IRender > GetRenderer(ERenderTarget target)
Returns first renderer in m_Renderers that renders to 'target'.
Definition: glresmgr.cpp:269
T Top() const
Definition: glrect.hpp:84
T Bottom() const
Definition: glrect.hpp:82
T Width() const
Definition: glrect.hpp:86
T Right() const
Definition: glrect.hpp:83
CGlRect< TVPUnit > TVPRect
Definition: gltypes.hpp:53
void AddRenderer(CIRef< IRender > rm)
Get/Set Renderer.
Definition: glresmgr.cpp:243
T Left() const
Definition: glrect.hpp:81
void SetCurrentRenderer(CIRef< IRender > rm)
Set current renderer (rm must already be in m_Renderers)
Definition: glresmgr.cpp:281
@ eRenderSVG
Definition: glstate.hpp:61
virtual void Finalize()
virtual void Initialize(const TVPRect &viewport)
void SetSimplified(bool simplified=true)
void Write(CNcbiOstream &ostrm)
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
#define _ASSERT
Modified on Fri Dec 08 08:21:10 2023 by modify_doxy.py rev. 669887