Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit 8c0969a

Browse files
HoumicekPavel-Holecekobergrd
authored
Invgen 44613 multi sheets (#312)
* Update 'ExportDrawingAsPDFplugin' to enable export all drawing sheets as PDF pages * INVGEN-45153 added prev/next drawing sheet buttons * added disabling of buttons when prev/next sheet is not available * Update Drawing test to cover multisheets functionality. Now we test Previous and Next arrows in the viewr tollbar. * PR fixes * lint fix * unit test fix * fixed UI test - added Done click Co-authored-by: Pavel Holecek <pavel.holecek@autodesk.com> Co-authored-by: David Obergries <david.obergries@autodesk.com>
1 parent c03bfe3 commit 8c0969a

File tree

10 files changed

+380
-18
lines changed

10 files changed

+380
-18
lines changed

AppBundles/ExportDrawingAsPdfPlugin/Automation.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public void RunWithArguments(Document doc, NameValueMap map)
7474
LogTrace("Drawing saved");
7575
var pdfPath = System.IO.Path.Combine(dir, "Drawing.pdf");
7676
LogTrace("Exporting drawing to: " + pdfPath);
77-
drawingDocument.SaveAs(pdfPath, true);
77+
ExportIDWToPDF(drawingDocument, pdfPath);
78+
//drawingDocument.SaveAs(pdfPath, true);
7879
LogTrace("Drawing exported");
7980
}
8081
}
@@ -102,6 +103,65 @@ private void ActivateDefaultProject(string dir)
102103
project.Activate(true);
103104
}
104105

106+
// Export Drawing file to PDF format
107+
// In case that the Drawing has more sheets -> it will export PDF with pages
108+
// Each PDF page represet one Drawing sheet
109+
public void ExportIDWToPDF(Document doc, string exportFileName)
110+
{
111+
if (doc == null)
112+
{
113+
LogError("Document is null!");
114+
return;
115+
}
116+
117+
LogTrace("PDF file full path : " + exportFileName);
118+
119+
LogTrace("Create PDF Translator Addin");
120+
TranslatorAddIn PDFAddIn = (TranslatorAddIn)inventorApplication.ApplicationAddIns.ItemById["{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"];
121+
122+
if (PDFAddIn == null)
123+
{
124+
LogError("Error: PDF Translator Addin is null!");
125+
return;
126+
}
127+
128+
TranslationContext context = inventorApplication.TransientObjects.CreateTranslationContext();
129+
NameValueMap options = inventorApplication.TransientObjects.CreateNameValueMap();
130+
if (PDFAddIn.HasSaveCopyAsOptions[doc, context, options])
131+
{
132+
context.Type = IOMechanismEnum.kFileBrowseIOMechanism;
133+
DataMedium dataMedium = inventorApplication.TransientObjects.CreateDataMedium();
134+
135+
options.Value["Sheet_Range"] = PrintRangeEnum.kPrintAllSheets;
136+
options.Value["Vector_Resolution"] = 300;
137+
138+
options.Value["All_Color_AS_Black"] = false;
139+
options.Value["Sheets"] = GetSheetOptions(doc);
140+
141+
dataMedium.FileName = exportFileName;
142+
LogTrace("Processing PDF export ...");
143+
PDFAddIn.SaveCopyAs(doc, context, options, dataMedium);
144+
LogTrace("Finish processing PDF export ...");
145+
}
146+
}
147+
148+
// Check if the Drawing file has more sheets
149+
private NameValueMap GetSheetOptions(Document doc)
150+
{
151+
DrawingDocument drawingDocument = doc as DrawingDocument;
152+
153+
NameValueMap sheets = inventorApplication.TransientObjects.CreateNameValueMap();
154+
foreach (Sheet sheet in drawingDocument.Sheets)
155+
{
156+
NameValueMap option = inventorApplication.TransientObjects.CreateNameValueMap();
157+
option.Add("Name", sheet.Name);
158+
option.Add("3DModel", false);
159+
sheets.Add("Sheet" + sheets.Count + 1, option);
160+
}
161+
162+
return sheets;
163+
}
164+
105165
#region Logging utilities
106166

107167
/// <summary>

AppBundles/ExportDrawingAsPdfPlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
[assembly: Guid("f1c9d7e2-53a8-4e4e-af9e-931ca891715d")]
88

9-
[assembly: AssemblyVersion("1.0.0.0")]
10-
[assembly: AssemblyFileVersion("1.0.0.0")]
9+
[assembly: AssemblyVersion("1.0.0.1")]
10+
[assembly: AssemblyFileVersion("1.0.0.1")]
Lines changed: 42 additions & 0 deletions
Loading
Lines changed: 42 additions & 0 deletions
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Autodesk, Inc. All rights reserved
3+
* Written by Forge Design Automation team for Inventor
4+
*
5+
* Permission to use, copy, modify, and distribute this software in
6+
* object code form for any purpose and without fee is hereby granted,
7+
* provided that the above copyright notice appears in all copies and
8+
* that both that copyright notice and the limited warranty and
9+
* restricted rights notice below appear in all supporting
10+
* documentation.
11+
*
12+
* AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
13+
* AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
14+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
15+
* DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
16+
* UNINTERRUPTED OR ERROR FREE.
17+
*/
18+
19+
/* the same styles*/
20+
.drawing-icon-prev, .drawing-icon-next {
21+
background-color: #f4f4f4;
22+
-webkit-mask-size: 22px;
23+
mask-size: 22px;
24+
-webkit-mask-repeat: no-repeat;
25+
mask-repeat: no-repeat;
26+
-webkit-mask-position: center;
27+
mask-position: center;
28+
}
29+
30+
/*if button is hovered, we need to set right icon background-color to have svg colored correctly*/
31+
.drawing-button-prev:hover .drawing-icon-prev, .drawing-button-next:hover .drawing-icon-next {
32+
background-color: #00bfff;
33+
}
34+
35+
.drawing-icon-prev {
36+
-webkit-mask-image: url(/prev.svg);
37+
mask-image: url(/prev.svg);
38+
}
39+
40+
.drawing-icon-next {
41+
-webkit-mask-image: url(/next.svg);
42+
mask-image: url(/next.svg);
43+
}

WebApplication/ClientApp/src/components/forgePdfView.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Script from 'react-load-script';
2121
import {connect} from 'react-redux';
2222
import { getDrawingPdfUrl } from '../reducers/mainReducer';
2323
import repo from '../Repository';
24+
import './forgePdfView.css';
2425

2526
let Autodesk = null;
2627

@@ -33,16 +34,22 @@ export class ForgePdfView extends Component {
3334
this.viewer = null;
3435
}
3536

36-
handleScriptLoad() {
37+
async handleScriptLoad() {
3738

3839
const options = repo.hasAccessToken() ?
3940
{ accessToken: repo.getAccessToken() } :
4041
{ env: 'Local' };
4142

4243
Autodesk = window.Autodesk;
4344

45+
try {
46+
await import('./forgePdfViewExtension');
47+
} catch (error) {
48+
// TODO unit test is crashing here, verify if some mock resolve it
49+
}
50+
4451
const container = this.viewerDiv.current;
45-
this.viewer = new Autodesk.Viewing.GuiViewer3D(container);
52+
this.viewer = new Autodesk.Viewing.GuiViewer3D(container, { extensions: ['ForgePdfViewExtension'] });
4653

4754
// uncomment this for Viewer debugging
4855
//this.viewer.debugEvents(true);
@@ -61,14 +68,14 @@ export class ForgePdfView extends Component {
6168

6269
this.viewer.loadExtension('Autodesk.PDF');
6370

64-
this.viewer.loadModel( this.props.drawingPdf , this.viewer);
71+
this.viewer.loadModel( this.props.drawingPdf);
6572
//this.viewer.loadExtension("Autodesk.Viewing.MarkupsCore")
6673
//this.viewer.loadExtension("Autodesk.Viewing.MarkupsGui")
6774
}
6875

6976
componentDidUpdate(prevProps) {
70-
if (Autodesk && (this.props.drawingPdf !== prevProps.drawingPdf)) {
71-
this.viewer.loadModel( this.props.drawingPdf , this.viewer);
77+
if (this.viewer && Autodesk && (this.props.drawingPdf !== prevProps.drawingPdf)) {
78+
this.viewer.loadModel( this.props.drawingPdf);
7279
}
7380
}
7481

WebApplication/ClientApp/src/components/forgePdfView.test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('components', () => {
5757
adskViewingShutdownMock.mockClear();
5858
});
5959

60-
it('load gets called when pdf provided', () => {
60+
it('load gets called when pdf provided', async () => {
6161
const wrapper = shallow(<ForgePdfView { ...baseProps } />);
6262

6363
const viewer = wrapper.find('.viewer');
@@ -66,35 +66,39 @@ describe('components', () => {
6666
expect(script).toHaveLength(1);
6767

6868
window.Autodesk = AutodeskMock;
69-
script.simulate('load');
69+
await script.simulate('load');
70+
await Promise.resolve(); // waits until all is done
71+
7072
expect(loadExtensionMock).toHaveBeenCalledWith('Autodesk.PDF');
7173
expect(loadModelMock).toHaveBeenCalledWith(drawingPdf);
7274
});
7375

74-
it('load gets called when pdf changes', () => {
76+
it('load gets called when pdf changes', async () => {
7577
const wrapper = shallow(<ForgePdfView { ...baseProps } />);
7678

7779
window.Autodesk = AutodeskMock;
7880
const script = wrapper.find('Script');
79-
script.simulate('load');
81+
await script.simulate('load');
82+
await Promise.resolve(); // waits until all is done
8083

8184
const updateProps = { drawingPdf: 'newurl.pdf' };
8285
wrapper.setProps(updateProps);
8386
expect(loadModelMock).toHaveBeenCalledTimes(2);
8487
});
8588

86-
it('returns without loading when pdf is null', () => {
89+
it('returns without loading when pdf is null', async () => {
8790
const nullProps = { drawingPdf: null };
8891
const wrapper = shallow(<ForgePdfView { ...nullProps } />);
8992

9093
window.Autodesk = AutodeskMock;
9194
const script = wrapper.find('Script');
92-
script.simulate('load');
95+
await script.simulate('load');
96+
await Promise.resolve(); // waits until all is done
9397

9498
expect(loadModelMock).toHaveBeenCalledTimes(0);
9599
});
96100

97-
it('unmounts correctly', () => {
101+
it('unmounts correctly', async () => {
98102
const wrapper = shallow(<ForgePdfView { ...baseProps } />);
99103

100104
// preparation: must load the viewer first
@@ -103,7 +107,8 @@ describe('components', () => {
103107
const script = viewer.find('Script');
104108
expect(script).toHaveLength(1);
105109
window.Autodesk = AutodeskMock;
106-
script.simulate('load');
110+
await script.simulate('load');
111+
await Promise.resolve(); // waits until all is done
107112

108113
wrapper.unmount();
109114

0 commit comments

Comments
 (0)