-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlockViewCommands.cpp
186 lines (165 loc) · 6.54 KB
/
BlockViewCommands.cpp
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
//
// (C) Copyright 2002-2006 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
///////////////////////////////////////////////
// ObjectARX defined commands
#include "StdAfx.h"
#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
//#error _DEBUG should not be defined except in internal Adesk debug builds
#endif
#include "StdArx.h"
#include "dbapserv.h"
#include "BlockViewDlg.h"
//////////////////////////////////////////////////////////////////////////
// This is command 'BLOCKVIEW' or 'BVIEW'
void AsdkBlockView()
{
//switch our resources to the foreground
CAcModuleResourceOverride overr;
//construct and display the preview dialog
CBlockViewDlg dlg;
dlg.DoModal();
}
// This is command 'CONFIGGS'
void AsdkConfigGS()
{
// get the GsManager from current MDI Client Window
AcGsManager *pGsMgr = acgsGetGsManager (NULL);
// if we go the gs manager ok
if (pGsMgr != NULL)
{
// get the Graphics Kernel
AcGsKernelDescriptor descriptor;
descriptor.addRequirement(AcGsKernelDescriptor::k3DDrawing);
AcGsGraphicsKernel *pGraphicsKernel = AcGsManager::acquireGraphicsKernel(descriptor);
// if we got it ok
if (pGraphicsKernel != NULL)
{
// now get the gs config class
AcGsConfig *pConfig = pGraphicsKernel->getConfig();
// if we got this ok too
if (pConfig != NULL)
{
// display the config dialog
pConfig->showConfigDialog();
}
}
}
}
//////////////////////////////////////////////////////////////////////////
// This is command 'RenderOffScreen' or 'ROS'
// Create an off screen AcGsDevice which we can render too
void AsdkRenderOffScreen()
{
// Obtain the current viewport's screen size. This will be the rendered image size.
AcDbObjectId curVportId = acedActiveViewportId();
AcDbObjectPointer<AcDbViewportTableRecord> curVport (curVportId,AcDb::kForRead);
int l,r,b,t;
acgsGetViewportInfo(curVport->number(),l,b,r,t);
int height = t - b - 1;
int width = r - l - 1;
// get the acgsManager
AcGsManager *gsManager = acgsGetGsManager();
// if ok
if (gsManager)
{
// get the graphics kernel
AcGsKernelDescriptor descriptor;
descriptor.addRequirement(AcGsKernelDescriptor::k3DDrawing);
AcGsGraphicsKernel *pGraphicsKernel = AcGsManager::acquireGraphicsKernel(descriptor);
// if ok
if (pGraphicsKernel)
{
// create a new off screen device
AcGsDevice *offDevice = pGraphicsKernel->createOffScreenDevice();
// if ok
if (offDevice)
{
// size it to what the user requires
offDevice->onSize(width, height);
// construct a simple view
AcGsView *pView = pGraphicsKernel->createView();
// if ok
if (pView)
{
pView->setVisualStyle(AcGiVisualStyle::kGouraud);
// set the device rendered to software
offDevice->setDeviceRenderer(AcGsDevice::kFullRender);
// add the gs view to the device
offDevice->add(pView);
// force update calls to all gsviews
offDevice->update();
// as the function suggests, create AutoCAD Model
AcGsModel *pModel = gsManager->createAutoCADModel(*pGraphicsKernel);
// if ok
if (pModel)
{
AcDbBlockTableRecordPointer spaceRec(curDoc()->database()->currentSpaceId(), AcDb::kForRead);
// if ok
if (spaceRec.openStatus() == Acad::eOk)
{
// add the current space AcDbBlockTableRecord to the gsview
pView->add(spaceRec, pModel);
// make sure it is closed
spaceRec.close();
// TODO: here you can set the visual style required
// record what the visual style was
AcDbObjectId defVisualStyle = pModel->visualStyle();
// now set it to something
pModel->setVisualStyle(defVisualStyle);
// set the AcGsView to have the same view target and postion as the *Active* AutoCAD view
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcGeMatrix3d viewMat;
SetViewTo(pView, pDb, viewMat);
// A Zoom extents to fill the frame to the offscreen device
AcDbExtents viewExtents(pDb->extmin(), pDb->extmax());
viewExtents.transformBy (viewMat);
pView->zoomExtents(viewExtents.minPoint(),viewExtents.maxPoint());
pView->zoom(0.95f);
refreshView(pView);
// send -1.0 to avoid dynamic tessellation while interactivity is enabled,
// regardless of whether degradation is enabled or not
pView->beginInteractivity(-1.0);
// get the filename to output
struct resbuf *result = NULL;
int status = acedGetFileNavDialog(_T("SnapShot"), NULL, _T("jpg;png;tif;bmp"), _T("BlockViewSnapshotBrowseDialog"), 1, &result);
if (status == RTNORM)
{
// make the filename var more friendly
ACHAR *pFileName = result->resval.rstring;
// create the image and write to disk
if (!CreateAtilImage(pView, width, height, 32, 0, pFileName, true))
AfxMessageBox(_T("Failed to create image..."));
}
}
}
// now do the various GS clean up ops
pView->eraseAll();
offDevice->erase(pView);
pGraphicsKernel->deleteView(pView);
pGraphicsKernel->deleteModel(pModel);
}
}
// finally
pGraphicsKernel->deleteDevice(offDevice);
}
}
}