DATAKIT API  V2025.1
PdfWriteLayout.cpp File Reference

Functions

void CreatePDFLayout (const Dtk_string &inFileName, Dtk_Int32 artworkIndex, std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_t > &inModelInventory)
 
void PdfWriteArray (Dtk_Size_t inNumLines, Dtk_Size_t inNumColumns, Dtk_Double64 inCellWidth, Dtk_Double64 inCellHeight, Dtk_tab< Dtk_tab< Dtk_string > > &inTabStrings, Dtk_Double64 inCharWidth, Dtk_Double64 inCharHeight, Dtk_tab< Dtk_tab< Dtk_pnt > > &outTabPoints, Dtk_pnt inOrigin, Dtk_RGB inColor)
 
Dtk_pnt PdfWriteCartridge (const Dtk_string &inFileName, std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_t > &inModelInventory)
 
void PdfWriteDtk_stringAsCompositeText (const Dtk_string &inString, Dtk_RGB textColor, Dtk_pnt location, Dtk_Double64 charWidth, Dtk_Double64 charHeight)
 
DtkErrorStatus PdfWritePicture (Dtk_string imageFullPathName, Dtk_Double64 pictureBBox[4])
 

Variables

std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_tmodelInventory
 

Function Documentation

◆ CreatePDFLayout()

void CreatePDFLayout ( const Dtk_string inFileName,
Dtk_Int32  artworkIndex,
std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_t > &  inModelInventory 
)
285 {
286 
287  //**************************************************************************************************************//
288  // Cartridge
289  //**************************************************************************************************************//
290  Dtk_pnt origin = PdfWriteCartridge(inFileName, inModelInventory);
291 
292 
293  //**************************************************************************************************************//
294  // 3D annotation creation
295  //**************************************************************************************************************//
296  if (artworkIndex > -1)
297  {//3D Annotation
298  //**************************************************************************************************************//
299  // Computing annotation Bounding Box
300  //**************************************************************************************************************//
301  Dtk_Double64 margin = 16.0, bottom, top, left, right;
302  bottom = origin[1];
303  left = margin;
304  right = Pdfw::Layout::GetCurrentPageWidth() - margin;
305  top = Pdfw::Layout::GetCurrentPageHeight() - margin;
306  Dtk_Double64 annotBBox[4] = { left, bottom, right, top };
307  //WARNING : no text must be added to current page after this 3d annotation or the result pdf file will have some errors in adobe reader....
308  Pdfw::Layout::Create3DAnnotation(artworkIndex, annotBBox);
309  }
310 }

◆ PdfWriteArray()

void PdfWriteArray ( Dtk_Size_t  inNumLines,
Dtk_Size_t  inNumColumns,
Dtk_Double64  inCellWidth,
Dtk_Double64  inCellHeight,
Dtk_tab< Dtk_tab< Dtk_string > > &  inTabStrings,
Dtk_Double64  inCharWidth,
Dtk_Double64  inCharHeight,
Dtk_tab< Dtk_tab< Dtk_pnt > > &  outTabPoints,
Dtk_pnt  inOrigin,
Dtk_RGB  inColor 
)
69 {
70  Dtk_tab<Dtk_PolylinePtr> tabPolylines;
71  Dtk_Size_t i, j;
72  Dtk_pnt location;
73  Dtk_dir xDir(1.0, 0.0);
74  Dtk_dir yDir(0.0, 1.0);
75  Dtk_Double64 lineThickness = 1.0;
76  outTabPoints.resize(inNumLines + 1);
77  location = inOrigin;
78  outTabPoints[0].resize(inNumColumns + 1);
79  for (j = 0; j < inNumColumns + 1; j++)
80  {
81  outTabPoints[0][j] = location + xDir * (j*inCellWidth);
82  }
83 
84  for (i = 0; i < inNumLines; i++)
85  {
86  location -= yDir * inCellHeight;
87 
88  outTabPoints[i + 1].resize(inNumColumns + 1);
89  for (j = 0; j < inNumColumns + 1; j++)
90  {
91  outTabPoints[i + 1][j] = (location + xDir * (j * inCellWidth));
92  }
93  location[0] = inOrigin[0];
94  }
95 
96  for (i = 0; i < inNumLines; i++)
97  {
98  Dtk_Double64 bbox[4];
99  bbox[0] = outTabPoints[i + 1][0].x();
100  bbox[1] = outTabPoints[i + 1][0].y();
101  bbox[2] = outTabPoints[i][1].x();
102  bbox[3] = outTabPoints[i][1].y();
103  Pdfw::Layout::FillRectangle(bbox, Dtk_RGB(200, 200, 200));
104  bbox[0] = outTabPoints[i + 1][1].x();
105  bbox[1] = outTabPoints[i + 1][1].y();
106  bbox[2] = outTabPoints[i][2].x();
107  bbox[3] = outTabPoints[i][2].y();
108  Pdfw::Layout::FillRectangle(bbox, Dtk_RGB(210, 210, 255));
109  }
110 
111  location = inOrigin;
112  for (i = 0; i < inNumLines; i++)
113  {
114  location -= yDir * inCellHeight;
115  for (j = 0; j < inNumColumns; j++)
116  {
117  Dtk_string &field = inTabStrings[i][j];
118  Dtk_Double64 offset = inCellHeight / 6;
119  PdfWriteDtk_stringAsCompositeText(field, Dtk_RGB(0, 0, 0), location + xDir*offset + yDir*offset, inCharWidth, inCharHeight);
120  location += xDir * inCellWidth;
121  }
122  location[0] = inOrigin[0];
123  }
124 
125  Dtk_PolylinePtr polyline = Dtk_Polyline::Create(outTabPoints[0][0], outTabPoints[0][inNumColumns]);
126  polyline->AddPoint(outTabPoints[inNumLines][inNumColumns]);
127  polyline->AddPoint(outTabPoints[inNumLines][0]);
128  polyline->AddPoint(outTabPoints[0][0]);
129  polyline->AddPoint(outTabPoints[0][inNumColumns]);
130  polyline->info() = Dtk_Info::create();
131  polyline->info()->SetCurveThickNessInMM(lineThickness);
132  tabPolylines.push_back(polyline);
133 
134  //lines
135  lineThickness = 0.2;
136  for (i = 0; i < inNumLines; i++)
137  {
138  polyline = Dtk_Polyline::Create(outTabPoints[i + 1][0], outTabPoints[i + 1][1]);
139  for (j = 2; j < inNumColumns + 1; j++)
140  {
141  polyline->AddPoint(outTabPoints[i + 1][j]);
142  }
143  polyline->info() = Dtk_Info::create();
144  polyline->info()->SetCurveThickNessInMM(lineThickness);
145  tabPolylines.push_back(polyline);
146  }
147  //columns
148  lineThickness = 1.0;
149  for (i = 0; i < inNumColumns; i++)
150  {
151  polyline = Dtk_Polyline::Create(outTabPoints[0][i + 1], outTabPoints[1][i + 1]);
152  for (j = 2; j < inNumLines + 1; j++)
153  {
154  polyline->AddPoint(outTabPoints[j][i + 1]);
155  }
156  polyline->info() = Dtk_Info::create();
157  polyline->info()->SetCurveThickNessInMM(lineThickness);
158  tabPolylines.push_back(polyline);
159  }
160 
161  Pdfw::Layout::WritePolylines(tabPolylines);
162 }

◆ PdfWriteCartridge()

Dtk_pnt PdfWriteCartridge ( const Dtk_string inFileName,
std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_t > &  inModelInventory 
)
168 {
169  Dtk_API * MyAPI = Dtk_API::GetAPI();
170  Dtk_tab < Dtk_tab < Dtk_string> > tabStrings;
171  Dtk_tab < Dtk_tab < Dtk_pnt> > tabPoints;
172  Dtk_Double64 charHeight = 5, charWidth = 4, cellHeight, cellWidth;
173  Dtk_Size_t numLines = 5, numColumns = 2;
174  Dtk_Size_t i;
175  Dtk_pnt origin;
176  Dtk_dir xDir(1, 0, 0), yDir(0, 1, 0);
177  Dtk_Double64 margin = 15.;
178  Dtk_RGB color(200, 200, 200);
179  Dtk_RGB textColor(0, 0, 128);
180  Dtk_pnt location(20., 90.0);
181 
182  cellHeight = charHeight + 13;
183  cellWidth = Pdfw::Layout::GetCurrentPageWidth() / 3;
184 
185  origin = Dtk_pnt(Pdfw::Layout::GetCurrentPageWidth() - margin - (numColumns*cellWidth), margin + (numLines*cellHeight));
186 
187  //**************************************************************************************************************//
188  // Background Picture creation
189  //**************************************************************************************************************//
190  Dtk_string imageFullPathName = "../InputImages/background.jpg";
191  Dtk_Double64 pictureBBox[4];
192  pictureBBox[0] = 0.0;
193  pictureBBox[1] = 0.0;
194  pictureBBox[2] = Pdfw::Layout::GetCurrentPageWidth();
195  pictureBBox[3] = Pdfw::Layout::GetCurrentPageHeight();
196  PdfWritePicture(imageFullPathName, pictureBBox);
197 
198 
199  //**************************************************************************************************************//
200  // Logo creation
201  //**************************************************************************************************************//
202  imageFullPathName = "../InputImages/logodtk.bmp";
203  pictureBBox[0] = 20.0;
204  pictureBBox[1] = 20.0;
205  pictureBBox[2] = 70.0;
206  pictureBBox[3] = 70.0;
207  PdfWritePicture(imageFullPathName, pictureBBox);
208 
209  //**************************************************************************************************************//
210  // Date of creation
211  //**************************************************************************************************************//
212  Dtk_string dtkVersion = MyAPI->GetVersion();
213  std::time_t t = std::time(0);
214  Dtk_string dateString = Dtk_string("Files converted by");
215  location = Dtk_pnt(78., 52.);
216  PdfWriteDtk_stringAsCompositeText(dateString, textColor, location, charWidth, charHeight);
217  dateString = "Datakit API (V" + dtkVersion + ") on :";
218  location -= 10 * yDir;
219  PdfWriteDtk_stringAsCompositeText(dateString, textColor, location, charWidth, charHeight);
220  char buffer[26]; // Buffer to store the formatted time
221 #if defined(_WIN32) || defined(_WIN64)
222  ctime_s(buffer, sizeof(buffer), &t);
223 #else
224  ctime_r(&t, buffer);
225 #endif
226  dateString = buffer;
227  location -= 10 * yDir;
228  PdfWriteDtk_stringAsCompositeText(dateString, textColor, location, charWidth, charHeight);
229 
230 
231  //**************************************************************************************************************//
232  // Frame
233  //**************************************************************************************************************//
234  Dtk_tab<Dtk_PolylinePtr>tabPolylines;
235  Dtk_PolylinePtr polyline = Dtk_Polyline::Create(Dtk_pnt(margin, margin), Dtk_pnt(margin, Pdfw::Layout::GetCurrentPageHeight() - margin));
236  polyline->AddPoint(Dtk_pnt(Pdfw::Layout::GetCurrentPageWidth() - margin, Pdfw::Layout::GetCurrentPageHeight() - margin));
237  polyline->AddPoint(Dtk_pnt(Pdfw::Layout::GetCurrentPageWidth() - margin, margin));
238  polyline->AddPoint(Dtk_pnt(margin, margin));
239  polyline->AddPoint(Dtk_pnt(margin, Pdfw::Layout::GetCurrentPageHeight() - margin));
240  polyline->info() = Dtk_Info::create();
241  polyline->info()->SetCurveThickNessInMM(2);
242  tabPolylines.push_back(polyline);
243 
244 
245  //**************************************************************************************************************//
246  // Array with Properties
247  //**************************************************************************************************************//
248 
249  //filling of tabstrings
250  tabStrings.resize(numLines);
251  for (i = 0; i < numLines; i++)
252  {
253  tabStrings[i].resize(numColumns);
254  }
255 
256  Dtk_string numBodies;
257  Dtk_string numMeshes;
258  Dtk_string numPMIs;
259  Dtk_string numDrawings;
260 
261  numBodies.add_int((int)inModelInventory[Dtk_Node::BodyType]);
262  numMeshes.add_int((int)inModelInventory[Dtk_Node::MeshType]);
263  numPMIs.add_int((int)inModelInventory[Dtk_Node::FdtType]);
264  numDrawings.add_int((int)inModelInventory[Dtk_Node::DrawingType]);
265 
266  tabStrings[0][0] = "Inventory"; tabStrings[0][1] = inFileName.filename() + inFileName.extension();
267  tabStrings[1][0] = "Number of processed BODIES"; tabStrings[1][1] = numBodies;
268  tabStrings[2][0] = "Number of processed MESHES"; tabStrings[2][1] = numMeshes;
269  tabStrings[3][0] = "Number of processed 3D PMIS"; tabStrings[3][1] = numPMIs;
270  tabStrings[4][0] = "Number of processed DRAWINGS"; tabStrings[4][1] = numDrawings;
271 
272  origin[0] = 206;
273  origin[1] = 85;
274  cellHeight = charHeight + 9;
275  cellWidth = (Pdfw::Layout::GetCurrentPageWidth() - origin[0] - margin) / 2;
276  PdfWriteArray(numLines, numColumns, cellWidth, cellHeight, tabStrings, charWidth, charHeight, tabPoints, origin, color);
277 
278  Pdfw::Layout::WritePolylines(tabPolylines);
279 
280  return origin;
281 }

◆ PdfWriteDtk_stringAsCompositeText()

void PdfWriteDtk_stringAsCompositeText ( const Dtk_string inString,
Dtk_RGB  textColor,
Dtk_pnt  location,
Dtk_Double64  charWidth,
Dtk_Double64  charHeight 
)
24 {
25  // Creation of Text info
26  Dtk_InfoPtr text_info = Dtk_Info::create();
27  //Setting text color to blue
28  text_info->SetColor(textColor);
29  //Setting text style
30  Dtk_Double64 slant = 1.;
31  Dtk_TextStyle text_style;
32  Dtk_CompositeText compoText;
33  Dtk_Double64 XLen = inString.len() * charWidth, YLen = charHeight;
34  Dtk_dir XDir(1., 0., 0.), YDir(0., 0., 1.);
35  Dtk_Oriented2dBBox inbox(location, XLen, YLen, XDir, YDir);
37  Dtk_bool horizontalOrVertical = 1;
38 
39  Dtk_Int32 pos = inString.find_substring("\n");
40  if (pos > 0)
41  {
42  Dtk_string leftString, rightString;
43  leftString = inString.Substring(0, pos);
44  rightString = inString.Substring(pos, inString.len());
45  Dtk_Text leftText = Dtk_Text(leftString, inbox, inbox, slant, horizontalOrVertical, text_type, text_info, text_style);
46  compoText.AddText(leftText);
47  Dtk_transfo transfo;
48  transfo.setOrigin(Dtk_pnt(inbox.GetBottomLeftPoint().x() - inbox.GetYLength(), inbox.GetBottomLeftPoint().y()));
49  inbox.Transform(transfo);
50  Dtk_Text rightText = Dtk_Text(rightString, inbox, inbox, slant, horizontalOrVertical, text_type, text_info, text_style);
51  compoText.AddText(rightText);
52  }
53  else
54  {
55  Dtk_Text text = Dtk_Text(inString, inbox, inbox, slant, horizontalOrVertical, text_type, text_info, text_style);
56  compoText.AddText(text);
57  }
58 
60 }

◆ PdfWritePicture()

DtkErrorStatus PdfWritePicture ( Dtk_string  imageFullPathName,
Dtk_Double64  pictureBBox[4] 
)
15 {
16  DtkErrorStatus errPict = Pdfw::Layout::WritePicture(imageFullPathName, pictureBBox);
17  if (errPict == dtkErrorFileNotExist)
18  cout << "Image File does not exist (" << imageFullPathName.c_str() << ")" << endl;
19 
20  return errPict;
21 }

Variable Documentation

◆ modelInventory

std::map<Dtk_Node::NodeDataTypeEnum, Dtk_Size_t> modelInventory
extern
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
Pdfw::Layout::Create3DAnnotation
DtkErrorStatus Create3DAnnotation(Dtk_UInt32 inArtworkIndex, Dtk_Double64 inBBox[4], Dtk_Int32 inModelDisplayIndex=-1, Dtk_Int32 inLayerID=-1, RenderMode inRenderMode=Unset, Lighting inLighting=UnsetLighting, Dtk_bool inAnnotActivation=0)
Creates 3D Annotation from 3D artwork in current page with its 2d bounding box.
Dtk_Node::FdtType
@ FdtType
Definition: dtk_maindoc.hpp:251
Dtk_TextStyle
This is the text_style. This class gathers several informations about text style.
Definition: util_draw_dtk.hpp:260
dtkErrorFileNotExist
@ dtkErrorFileNotExist
Definition: error_dtk.hpp:95
Dtk_transfo::setOrigin
void setOrigin(const Dtk_pnt &O)
Set a new O center point.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Pdfw::Layout::GetCurrentPageWidth
Dtk_Double64 GetCurrentPageWidth()
Gets current page width.
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Pdfw::Layout::GetCurrentPageHeight
Dtk_Double64 GetCurrentPageHeight()
Gets current page height.
PdfWriteDtk_stringAsCompositeText
void PdfWriteDtk_stringAsCompositeText(const Dtk_string &inString, Dtk_RGB textColor, Dtk_pnt location, Dtk_Double64 charWidth, Dtk_Double64 charHeight)
Definition: PdfWriteLayout.cpp:23
Dtk_Text
This is the base text class. It's part of Dtk_CompositeText. It's used into a lot of 2D Entities It c...
Definition: util_draw_dtk.hpp:1126
PdfWritePicture
DtkErrorStatus PdfWritePicture(Dtk_string imageFullPathName, Dtk_Double64 pictureBBox[4])
Definition: PdfWriteLayout.cpp:14
Dtk_Node::BodyType
@ BodyType
Definition: dtk_maindoc.hpp:248
Dtk_bool
char Dtk_bool
Definition: define.h:725
Dtk_Double64
double Dtk_Double64
Definition: define.h:699
Dtk_string::find_substring
int find_substring(const Dtk_string &s1) const
find the position of a substring into a Dtk_string
Pdfw::Layout::WritePicture
Dtk_ErrorStatus WritePicture(Dtk_string inPicturePath, Dtk_Double64 inPictureBBox[4])
Write a picture.
Dtk_string::add_int
void add_int(const int integer, int force_unsigned_int=0)
concat an int to the Dtk_string (convert the int to Dtk_string)
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
Pdfw::Layout::WriteCompositeText
Dtk_ErrorStatus WriteCompositeText(Dtk_CompositeText &inCompositeText)
Write a composite text.
DTK_Text_type
DTK_Text_type
Definition: str_def.h:11
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:687
Dtk_tab::resize
void resize(Dtk_Size_t n, const T &t)
Resizes the array.
Definition: util_stl_dtk.hpp:603
Pdfw::Layout::WritePolylines
Dtk_ErrorStatus WritePolylines(Dtk_tab< Dtk_PolylinePtr > &inTabPolylines)
Write a set of polylines.
PdfWriteArray
void PdfWriteArray(Dtk_Size_t inNumLines, Dtk_Size_t inNumColumns, Dtk_Double64 inCellWidth, Dtk_Double64 inCellHeight, Dtk_tab< Dtk_tab< Dtk_string > > &inTabStrings, Dtk_Double64 inCharWidth, Dtk_Double64 inCharHeight, Dtk_tab< Dtk_tab< Dtk_pnt > > &outTabPoints, Dtk_pnt inOrigin, Dtk_RGB inColor)
Definition: PdfWriteLayout.cpp:62
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_API::GetVersion
Dtk_string GetVersion() const
GetVersion of DatakitLibs.
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
Dtk_Polyline::Create
static Dtk_PolylinePtr Create(const Dtk_Polyline &inPolylineToCopy)
constructors returning Smart pointers
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
Pdfw::Layout::FillRectangle
Dtk_ErrorStatus FillRectangle(Dtk_Double64 inBBox[4], Dtk_RGB inColor)
Fills a rectangle area with color.
Dtk_string::extension
Dtk_string extension() const
File Utility : Retrieves the extension in Dtk_string form.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
Dtk_CompositeText
This is the composite text class. It's basically a Dtk_Text Container. This class represents a group ...
Definition: util_draw_dtk.hpp:1557
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_string::Substring
Dtk_string Substring(const Dtk_Size_t &inStartIndex, const Dtk_Size_t &inLength) const
dtk_text_type_undefined
@ dtk_text_type_undefined
Definition: str_def.h:25
Dtk_string::len
int len() const
Retrieve the length of the Dtk_string.
PdfWriteCartridge
Dtk_pnt PdfWriteCartridge(const Dtk_string &inFileName, std::map< Dtk_Node::NodeDataTypeEnum, Dtk_Size_t > &inModelInventory)
Definition: PdfWriteLayout.cpp:166
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:415
Dtk_CompositeText::AddText
void AddText(Dtk_Text inText)
Adds a Dtk_Text to the Dtk_CompositeText.
Dtk_RGB
Definition: dtk_rgb.hpp:7
Dtk_Info::SetColor
Dtk_ErrorStatus SetColor(const int &R, const int &G, const int &B)
Dtk_Node::DrawingType
@ DrawingType
Definition: dtk_maindoc.hpp:252
Dtk_Info::create
static Dtk_SmartPtr< Dtk_Info > create()
Dtk_Oriented2dBBox
This is the base bounding box class. It's used into a lot of 2D Entities This class represents the ba...
Definition: util_draw_dtk.hpp:479
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
Dtk_Node::MeshType
@ MeshType
Definition: dtk_maindoc.hpp:249
Dtk_API
Definition: dtk_api.hpp:75