-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrender.cpp
More file actions
executable file
·850 lines (726 loc) · 24.3 KB
/
render.cpp
File metadata and controls
executable file
·850 lines (726 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
/****************************************************************************
**
** Copyright (C) 2007-2009 Kevin Clague. All rights reserved.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
/****************************************************************************
*
* This class encapsulates the external renderers. For now, this means
* only ldglite.
*
* Please see lpub.h for an overall description of how the files in LPub
* make up the LPub program.
*
***************************************************************************/
#include <QtGui>
#include <QString>
#include <QStringList>
#include <QPixmap>
#include <QProcess>
#include <QFile>
#include <QTextStream>
#include "render.h"
#include "resolution.h"
#include "meta.h"
#include "math.h"
#include "lpub.h"
#include "lpub_preferences.h"
#include "paths.h"
#ifdef _WIN32
#include <windows.h>
#endif
Render *renderer;
LDGLite ldglite;
LDView ldview;
L3P l3p;
//#define LduDistance 5729.57
#define CA "-ca0.01"
#define USE_ALPHA "+UA"
static double pi = 4*atan(1.0);
// the default camera distance for real size
static float LduDistance = 10.0/tan(0.005*pi/180);
QString fixupDirname(const QString &dirNameIn) {
#ifndef _WIN32
return dirNameIn;
#else
long length = 0;
TCHAR* buffer = NULL;
LPCWSTR dirNameWin = dirNameIn.utf16();
// First obtain the size needed by passing NULL and 0.
length = GetShortPathName(dirNameWin, NULL, 0);
if (length == 0){
qDebug() << "Couldn't get length of short path name, trying long path name\n";
return dirNameIn;
}
// Dynamically allocate the correct size
// (terminating null char was included in length)
buffer = new TCHAR[length];
// Now simply call again using same long path.
length = GetShortPathName(dirNameWin, buffer, length);
if (length == 0){
qDebug() << "Couldn't get short path name, trying long path name\n";
return dirNameIn;
}
QString dirNameOut = QString::fromWCharArray(buffer);
delete [] buffer;
return dirNameOut;
#endif
}
QString const Render::getRenderer()
{
if (renderer == &ldglite) {
return "LDGLite";
} else if (renderer == &ldview){
return "LDView";
} else {
return "L3P";
}
}
void Render::setRenderer(QString const &name)
{
if (name == "LDGLite") {
renderer = &ldglite;
} else if (name == "LDView") {
renderer = &ldview;
} else {
renderer = &l3p;
}
}
void clipImage(QString const &pngName){
//printf("\n");
QImage toClip(QDir::toNativeSeparators(pngName));
QRect clipBox = toClip.rect();
//printf("clipping %s from %d x %d at (%d,%d)\n",qPrintable(QDir::toNativeSeparators(pngName)),clipBox.width(),clipBox.height(),clipBox.x(),clipBox.y());
int x,y;
int initLeft = clipBox.left();
int initTop = clipBox.top();
int initRight = clipBox.right();
int initBottom = clipBox.bottom();
for(x = initLeft; x < initRight; x++){
for(y = initTop; y < initBottom; y++){
QRgb pixel = toClip.pixel(x, y);
if(!toClip.valid(x,y) || !QColor::fromRgba(pixel).isValid()){
//printf("something blew up when scanning at (%d,%d) - got %d %d\n",x,y,toClip.valid(x,y),QColor::fromRgba(pixel).isValid());
}
if ( pixel != 0){
//printf("bumped into something at (%d,%d)\n",x,y);
break;
}
}
if (y != initBottom) {
clipBox.setLeft(x);
break;
}
}
//printf("clipped to %d x %d at (%d,%d)\n",clipBox.width(),clipBox.height(),clipBox.x(),clipBox.y());
initLeft = clipBox.left();
for(x = initRight; x >= initLeft; x--){
for(y = initTop; y < initBottom; y++){
QRgb pixel = toClip.pixel(x, y);
if(!toClip.valid(x,y) || !QColor::fromRgba(pixel).isValid()){
//printf("something blew up when scanning at (%d,%d) - got %d %d\n",x,y,toClip.valid(x,y),QColor::fromRgba(pixel).isValid());
}
if ( pixel != 0){
//printf("bumped into something at (%d,%d)\n",x,y);
break;
}
}
if (y != initBottom) {
clipBox.setRight(x);
break;
}
}
//printf("clipped to %d x %d at (%d,%d)\n",clipBox.width(),clipBox.height(),clipBox.x(),clipBox.y());
initRight = clipBox.right();
for(y = initTop; y < initBottom; y++){
for(x = initLeft; x < initRight; x++){
QRgb pixel = toClip.pixel(x, y);
if(!toClip.valid(x,y) || !QColor::fromRgba(pixel).isValid()){
//printf("something blew up when scanning at (%d,%d) - got %d %d\n",x,y,toClip.valid(x,y),QColor::fromRgba(pixel).isValid());
}
if ( pixel != 0){
//printf("bumped into something at (%d,%d)\n",x,y);
break;
}
}
if (x != initRight) {
clipBox.setTop(y);
break;
}
}
//printf("clipped to %d x %d at (%d,%d)\n",clipBox.width(),clipBox.height(),clipBox.x(),clipBox.y());
initTop = clipBox.top();
for(y = initBottom; y >= initTop; y--){
for(x = initLeft; x < initRight; x++){
QRgb pixel = toClip.pixel(x, y);
if(!toClip.valid(x,y) || !QColor::fromRgba(pixel).isValid()){
//printf("something blew up when scanning at (%d,%d) - got %d %d\n",x,y,toClip.valid(x,y),QColor::fromRgba(pixel).isValid());
}
if ( pixel != 0){
//printf("bumped into something at (%d,%d)\n",x,y);
break;
}
}
if (x != initRight) {
clipBox.setBottom(y);
break;
}
}
//printf("clipped to %d x %d at (%d,%d)\n\n",clipBox.width(),clipBox.height(),clipBox.x(),clipBox.y());
QImage clipped = toClip.copy(clipBox);
//toClip.save(QDir::toNativeSeparators(pngName+"-orig.png"));
clipped.save(QDir::toNativeSeparators(pngName));
}
// Shared calculations
float stdCameraDistance(Meta &meta, float scale) {
float onexone;
float factor;
// Do the math in pixels
onexone = 20*meta.LPub.resolution.ldu(); // size of 1x1 in units
onexone *= meta.LPub.resolution.value(); // size of 1x1 in pixels
onexone *= scale;
factor = meta.LPub.page.size.valuePixels(0)/onexone; // in pixels;
return factor*LduDistance;
}
/***************************************************************************
*
* The math for zoom factor. 1.0 is true size.
*
* 1 LDU is 1/64 of an inch
*
* LDGLite produces 72 DPI
*
* Camera angle is 0.01
*
* What distance do we need to put the camera, given a user chosen DPI,
* to get zoom factor of 1.0?
*
**************************************************************************/
/***************************************************************************
*
* L3P renderer
*
**************************************************************************/
float L3P::cameraDistance(Meta &meta, float scale){
return stdCameraDistance(meta, scale);
}
int L3P::renderCsi(
const QString &addLine,
const QStringList &csiParts,
const QString &pngName,
Meta &meta){
/* Create the CSI DAT file */
QString ldrName;
int rc;
ldrName = QDir::currentPath() + "/" + Paths::tmpDir + "/csi.ldr";
QString povName = ldrName +".pov";
if ((rc = rotateParts(addLine,meta.rotStep, csiParts, ldrName)) < 0) {
return rc;
}
/* determine camera distance */
QStringList arguments;
bool hasLGEO = Preferences::lgeoPath != "";
int cd = cameraDistance(meta, meta.LPub.assem.modelScale.value());
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
float ar = width/(float)height;
QString cg = QString("-cg0.0,0.0,%1").arg(cd);
QString car = QString("-car%1").arg(ar);
QString ldd = QString("-ldd%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::ldrawPath)));
arguments << CA;
arguments << cg;
arguments << "-ld";
if(hasLGEO){
QString lgd = QString("-lgd%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath)));
arguments << "-lgeo";
arguments << lgd;
}
arguments << car;
arguments << "-o";
arguments << ldd;
QStringList list;
list = meta.LPub.assem.l3pParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << fixupDirname(QDir::toNativeSeparators(ldrName));
arguments << fixupDirname(QDir::toNativeSeparators(povName));
QProcess l3p;
QStringList env = QProcess::systemEnvironment();
l3p.setEnvironment(env);
l3p.setWorkingDirectory(QDir::currentPath()+"/"+Paths::tmpDir);
l3p.setStandardErrorFile(QDir::currentPath() + "/stderr");
l3p.setStandardOutputFile(QDir::currentPath() + "/stdout");
qDebug() << qPrintable(Preferences::l3pExe + " " + arguments.join(" ")) << "\n";
l3p.start(Preferences::l3pExe,arguments);
if ( ! l3p.waitForFinished(6*60*1000)) {
if (l3p.exitCode() != 0) {
QByteArray status = l3p.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("L3P failed with code %1\n%2").arg(l3p.exitCode()) .arg(str));
return -1;
}
}
QStringList povArguments;
QString O =QString("+O%1").arg(fixupDirname(QDir::toNativeSeparators(pngName)));
QString I = QString("+I%1").arg(fixupDirname(QDir::toNativeSeparators(povName)));
QString W = QString("+W%1").arg(width);
QString H = QString("+H%1").arg(height);
povArguments << I;
povArguments << O;
povArguments << W;
povArguments << H;
povArguments << USE_ALPHA;
if(hasLGEO){
QString lgeoLg = QString("+L%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath + "/lg")));
QString lgeoAr = QString("+L%2").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath + "/ar")));
povArguments << lgeoLg;
povArguments << lgeoAr;
}
#ifndef __APPLE__
povArguments << "/EXIT";
#endif
list = meta.LPub.assem.povrayParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
povArguments << list[i];
}
}
QProcess povray;
QStringList povEnv = QProcess::systemEnvironment();
povray.setEnvironment(povEnv);
povray.setWorkingDirectory(QDir::currentPath()+"/"+Paths::tmpDir);
povray.setStandardErrorFile(QDir::currentPath() + "/stderr-povray");
povray.setStandardOutputFile(QDir::currentPath() + "/stdout-povray");
qDebug() << qPrintable(Preferences::povrayExe + " " + povArguments.join(" ")) << "\n";
povray.start(Preferences::povrayExe,povArguments);
if ( ! povray.waitForFinished(6*60*1000)) {
if (povray.exitCode() != 0) {
QByteArray status = povray.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("POV-RAY failed with code %1\n%2").arg(povray.exitCode()) .arg(str));
return -1;
}
}
clipImage(pngName);
return 0;
}
int L3P::renderPli(const QString &ldrName,
const QString &pngName,
Meta &meta,
bool bom){
QString povName = ldrName +".pov";
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
float ar = width/(float)height;
/* determine camera distance */
PliMeta &pliMeta = bom ? meta.LPub.bom : meta.LPub.pli;
int cd = cameraDistance(meta,pliMeta.modelScale.value());
QString cg = QString("-cg%1,%2,%3") .arg(pliMeta.angle.value(0))
.arg(pliMeta.angle.value(1))
.arg(cd);
QString car = QString("-car%1").arg(ar);
QString ldd = QString("-ldd%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::ldrawPath)));
QStringList arguments;
bool hasLGEO = Preferences::lgeoPath != "";
arguments << CA;
arguments << cg;
arguments << "-ld";
if(hasLGEO){
QString lgd = QString("-lgd%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath)));
arguments << "-lgeo";
arguments << lgd;
}
arguments << car;
arguments << "-o";
arguments << ldd;
QStringList list;
list = meta.LPub.assem.l3pParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << fixupDirname(QDir::toNativeSeparators(ldrName));
arguments << fixupDirname(QDir::toNativeSeparators(povName));
QProcess l3p;
QStringList env = QProcess::systemEnvironment();
l3p.setEnvironment(env);
l3p.setWorkingDirectory(QDir::currentPath());
l3p.setStandardErrorFile(QDir::currentPath() + "/stderr");
l3p.setStandardOutputFile(QDir::currentPath() + "/stdout");
qDebug() << qPrintable(Preferences::l3pExe + " " + arguments.join(" ")) << "\n";
l3p.start(Preferences::l3pExe,arguments);
if (! l3p.waitForFinished()) {
if (l3p.exitCode()) {
QByteArray status = l3p.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("L3P failed\n%1") .arg(str));
return -1;
}
}
QStringList povArguments;
QString O =QString("+O%1").arg(fixupDirname(QDir::toNativeSeparators(pngName)));
QString I = QString("+I%1").arg(fixupDirname(QDir::toNativeSeparators(povName)));
QString W = QString("+W%1").arg(width);
QString H = QString("+H%1").arg(height);
povArguments << I;
povArguments << O;
povArguments << W;
povArguments << H;
povArguments << USE_ALPHA;
if(hasLGEO){
QString lgeoLg = QString("+L%1").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath + "/lg")));
QString lgeoAr = QString("+L%2").arg(fixupDirname(QDir::toNativeSeparators(Preferences::lgeoPath + "/ar")));
povArguments << lgeoLg;
povArguments << lgeoAr;
}
#ifndef __APPLE__
povArguments << "/EXIT";
#endif
list = meta.LPub.assem.povrayParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
povArguments << list[i];
}
}
QProcess povray;
QStringList povEnv = QProcess::systemEnvironment();
povray.setEnvironment(povEnv);
povray.setWorkingDirectory(QDir::currentPath()+"/"+Paths::tmpDir);
povray.setStandardErrorFile(QDir::currentPath() + "/stderr-povray");
povray.setStandardOutputFile(QDir::currentPath() + "/stdout-povray");
qDebug() << qPrintable(Preferences::povrayExe + " " + povArguments.join(" ")) << "\n";
povray.start(Preferences::povrayExe,povArguments);
if ( ! povray.waitForFinished(6*60*1000)) {
if (povray.exitCode() != 0) {
QByteArray status = povray.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("POV-RAY failed\n%1") .arg(str));
return -1;
}
}
clipImage(pngName);
return 0;
}
/***************************************************************************
*
* LDGLite renderer
*
**************************************************************************/
float LDGLite::cameraDistance(
Meta &meta,
float scale)
{
return stdCameraDistance(meta,scale);
}
int LDGLite::renderCsi(
const QString &addLine,
const QStringList &csiParts,
const QString &pngName,
Meta &meta)
{
/* Create the CSI DAT file */
QString ldrName;
int rc;
ldrName = QDir::currentPath() + "/" + Paths::tmpDir + "/csi.ldr";
if ((rc = rotateParts(addLine,meta.rotStep, csiParts, ldrName)) < 0) {
return rc;
}
/* determine camera distance */
QStringList arguments;
int cd = cameraDistance(meta,meta.LPub.assem.modelScale.value());
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
QString v = QString("-v%1,%2") .arg(width)
.arg(height);
QString o = QString("-o0,-%1") .arg(height/6);
QString mf = QString("-mF%1") .arg(pngName);
int lineThickness = resolution()/150+0.5;
if (lineThickness == 0) {
lineThickness = 1;
}
// ldglite always deals in 72 DPI
QString w = QString("-W%1") .arg(lineThickness);
QString cg = QString("-cg0.0,0.0,%1") .arg(cd);
arguments << "-l3";
arguments << "-i2";
arguments << CA;
arguments << cg;
arguments << "-J";
arguments << v;
arguments << o;
arguments << w;
arguments << "-q";
QStringList list;
list = meta.LPub.assem.ldgliteParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << mf;
arguments << ldrName;
QProcess ldglite;
QStringList env = QProcess::systemEnvironment();
env << "LDRAWDIR=" + Preferences::ldrawPath;
ldglite.setEnvironment(env);
ldglite.setWorkingDirectory(QDir::currentPath()+"/"+Paths::tmpDir);
ldglite.setStandardErrorFile(QDir::currentPath() + "/stderr");
ldglite.setStandardOutputFile(QDir::currentPath() + "/stdout");
ldglite.start(Preferences::ldgliteExe,arguments);
if ( ! ldglite.waitForFinished(6*60*1000)) {
if (ldglite.exitCode() != 0) {
QByteArray status = ldglite.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("LDGlite failed\n%1") .arg(str));
return -1;
}
}
//QFile::remove(ldrName);
return 0;
}
int LDGLite::renderPli(
const QString &ldrName,
const QString &pngName,
Meta &meta,
bool bom)
{
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
/* determine camera distance */
PliMeta &pliMeta = bom ? meta.LPub.bom : meta.LPub.pli;
int cd = cameraDistance(meta,pliMeta.modelScale.value());
QString cg = QString("-cg%1,%2,%3") .arg(pliMeta.angle.value(0))
.arg(pliMeta.angle.value(1))
.arg(cd);
QString v = QString("-v%1,%2") .arg(width)
.arg(height);
QString o = QString("-o0,-%1") .arg(height/6);
QString mf = QString("-mF%1") .arg(pngName);
// ldglite always deals in 72 DPI
QString w = QString("-W%1") .arg(int(resolution()/72.0+0.5));
QStringList arguments;
arguments << "-l3";
arguments << "-i2";
arguments << CA;
arguments << cg;
arguments << "-J";
arguments << v;
arguments << o;
arguments << w;
arguments << "-q";
QStringList list;
list = meta.LPub.pli.ldgliteParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << mf;
arguments << ldrName;
QProcess ldglite;
QStringList env = QProcess::systemEnvironment();
env << "LDRAWDIR=" + Preferences::ldrawPath;
ldglite.setEnvironment(env);
ldglite.setWorkingDirectory(QDir::currentPath());
ldglite.setStandardErrorFile(QDir::currentPath() + "/stderr");
ldglite.setStandardOutputFile(QDir::currentPath() + "/stdout");
ldglite.start(Preferences::ldgliteExe,arguments);
if (! ldglite.waitForFinished()) {
if (ldglite.exitCode()) {
QByteArray status = ldglite.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("LDGlite failed\n%1") .arg(str));
return -1;
}
}
return 0;
}
/***************************************************************************
*
* LDView renderer
* 6x6 5990
* LDView LDView LDGLite LDView
* 0.1 8x5 8x6 32x14 40x19 0.25 216x150 276x191 0.28
* 0.2 14x10 16x10 430x298 552x381
* 0.3 20x14 20x15 644x466 824x571
* 0.4 28x18 28x19 859x594 1100x762
* 0.5 34x22 36x22 1074x744 1376x949 0.28
* 0.6 40x27 40x28 1288x892
* 0.7 46x31 48x32 1502x1040
* 0.8 54x35 56x37
* 0.9 60x40 60x41
* 1.0 66x44 68x46 310x135 400x175 0.29
* 1.1 72x48
* 1.2 80x53
* 1.3 86x57
* 1.4 92x61
* 1.5 99x66
* 1.6 106x70
* 2.0 132x87 132x90 620x270 796x348 0.28
* 3.0 197x131 200x134 930x404 1169x522
* 4.0 262x174 268x178 1238x539 1592x697 0.29
* 5.0 328x217 332x223 1548x673
*
*
**************************************************************************/
float LDView::cameraDistance(
Meta &meta,
float scale)
{
return stdCameraDistance(meta, scale)*0.775;
}
int LDView::renderCsi(
const QString &addLine,
const QStringList &csiParts,
const QString &pngName,
Meta &meta)
{
/* Create the CSI DAT file */
QString ldrName;
int rc;
ldrName = QDir::currentPath() + "/" + Paths::tmpDir + "/csi.ldr";
if ((rc = rotateParts(addLine,meta.rotStep, csiParts, ldrName)) < 0) {
return rc;
}
/* determine camera distance */
QStringList arguments;
int cd = cameraDistance(meta,meta.LPub.assem.modelScale.value())*1700/1000;
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
QString w = QString("-SaveWidth=%1") .arg(width);
QString h = QString("-SaveHeight=%1") .arg(height);
QString s = QString("-SaveSnapShot=%1") .arg(pngName);
QString cg = QString("-cg0.0,0.0,%1") .arg(cd);
arguments << CA;
arguments << cg;
arguments << "-SaveAlpha=1";
arguments << "-AutoCrop=1";
arguments << "-ShowHighlightLines=1";
arguments << "-ConditionalHighlights=1";
arguments << "-SaveZoomToFit=0";
arguments << "-SubduedLighting=1";
arguments << "-UseSpecular=0";
arguments << "-LightVector=0,1,1";
arguments << "-SaveActualSize=0";
arguments << w;
arguments << h;
arguments << s;
QStringList list;
list = meta.LPub.assem.ldviewParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << ldrName;
QProcess ldview;
ldview.setEnvironment(QProcess::systemEnvironment());
ldview.setWorkingDirectory(QDir::currentPath()+"/"+Paths::tmpDir);
ldview.start(Preferences::ldviewExe,arguments);
if ( ! ldview.waitForFinished(6*60*1000)) {
if (ldview.exitCode() != 0 || 1) {
QByteArray status = ldview.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("LDView failed\n%1") .arg(str));
return -1;
}
}
//QFile::remove(ldrName);
return 0;
}
int LDView::renderPli(
const QString &ldrName,
const QString &pngName,
Meta &meta,
bool bom)
{
int width = meta.LPub.page.size.valuePixels(0);
int height = meta.LPub.page.size.valuePixels(1);
QFileInfo fileInfo(ldrName);
if ( ! fileInfo.exists()) {
return -1;
}
/* determine camera distance */
PliMeta &pliMeta = bom ? meta.LPub.bom : meta.LPub.pli;
int cd = cameraDistance(meta,pliMeta.modelScale.value())*1700/1000;
QString cg = QString("-cg%1,%2,%3") .arg(pliMeta.angle.value(0))
.arg(pliMeta.angle.value(1))
.arg(cd);
QString w = QString("-SaveWidth=%1") .arg(width);
QString h = QString("-SaveHeight=%1") .arg(height);
QString s = QString("-SaveSnapShot=%1") .arg(pngName);
QStringList arguments;
arguments << CA;
arguments << cg;
arguments << "-SaveAlpha=1";
arguments << "-AutoCrop=1";
arguments << "-ShowHighlightLines=1";
arguments << "-ConditionalHighlights=1";
arguments << "-SaveZoomToFit=0";
arguments << "-SubduedLighting=1";
arguments << "-UseSpecular=0";
arguments << "-LightVector=0,1,1";
arguments << "-SaveActualSize=0";
arguments << w;
arguments << h;
arguments << s;
QStringList list;
list = meta.LPub.pli.ldviewParms.value().split("\\s+");
for (int i = 0; i < list.size(); i++) {
if (list[i] != "" && list[i] != " ") {
arguments << list[i];
}
}
arguments << ldrName;
QProcess ldview;
ldview.setEnvironment(QProcess::systemEnvironment());
ldview.setWorkingDirectory(QDir::currentPath());
ldview.start(Preferences::ldviewExe,arguments);
if ( ! ldview.waitForFinished()) {
if (ldview.exitCode() != 0) {
QByteArray status = ldview.readAll();
QString str;
str.append(status);
QMessageBox::warning(NULL,
QMessageBox::tr("LPub"),
QMessageBox::tr("LDView failed\n%1") .arg(str));
return -1;
}
}
return 0;
}