CFx SDK Documentation  2020SP3
RemoteGeomProxy.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 #ifndef _ODREMOTEGEOMPROXY_INCLUDED_
26 #define _ODREMOTEGEOMPROXY_INCLUDED_
27 
28 #include "TD_PackPush.h"
29 
30 #include "Gi/GiWorldDraw.h"
31 #include "DbDatabase.h"
32 #include "SmartPtr.h"
33 #include "Ge/GeCircArc2d.h"
34 #include "UInt8Array.h"
35 
38 
48 protected:
51 public:
52 
53  // For the internal use.
54  enum Opcode {
57  };
58 
59  // Constructor.
62 
63  // Initialize reference database that is used for some operations (e.g. font rendering).
64  // If you certain that such operations would not be executed you can omit it.
65  void setDatabase(OdDbDatabase* pDb);
66 
67  // Initializes collecting geometry to send.
68  void begin();
69 
70  // Returns OdGiWorldDraw object to output geometry to
72 
73  // Returns OdGiWorldGeometry object to output geometry to.
74  // Shortcut for wDraw().geometry() expression.
76 
77  // Returns OdGiSubEntityTraits object to output geometry to.
78  // Shortcut for wDraw().subEntityTraits() expression.
80 
81  // Sends geometry collected since last call of begin() method to
82  // Remote Geometry Viewer over the named pipe.
83  void end();
84 
85  // Sends a string for execution to Remote Geometry Viewer.
86  // That string will be send to execution to RX command line engine.
87  // See OdEdCommandStack for detailes.
88  void sendStringToExecute( const OdString& s );
89 };
90 
91 static const OdString g_strGeomBlockBegin = OD_T("rblock_begin");
92 static const OdString g_strGeomBlockEnd = OD_T("rblock_end");
93 
99 {
100  OdRemoteGeomProxy* m_pProxy;
101 
102 public:
104  {
105  m_pProxy->sendStringToExecute(g_strGeomBlockBegin);
106  }
107 
109  {
110  m_pProxy->sendStringToExecute(g_strGeomBlockEnd);
111  }
112 
113 };
114 
115 inline
117 {
118 }
119 
120 inline
122 {
123 }
124 
125 inline void
127  m_pDb = pDb;
128 }
129 
132 }
133 
134 inline OdGiWorldDraw&
136  return *m_pWd;
137 }
138 
139 inline OdGiWorldGeometry&
141  return m_pWd->geometry();
142 }
143 
144 inline OdGiSubEntityTraits&
146  return m_pWd->subEntityTraits();
147 }
148 
149 inline void
151 {
152 #if defined(_WIN32) && !defined(_WINRT) && !defined(_WIN32_WCE)
153 
154  if( m_pWd.get() )
155  {
156  HANDLE hBufferWritten = ::OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, L"OdaRemoteGeometryBufferWrittenEvent");
157  HANDLE hBufferProcessed = ::OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, L"OdaRemoteGeometryBufferProcessedEvent");
158 
159  if(hBufferWritten != NULL && hBufferProcessed != NULL)
160  {
161  ::WaitForSingleObject(hBufferProcessed, INFINITE);
162  //::ResetEvent(hBufferProcessed);
163 
164  HANDLE hIPCFile = ::OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, L"OdaRemoteGeometryViewerIPCBuffer");
165  if(hIPCFile != NULL)
166  {
167  void* pBuffer = ::MapViewOfFile(hIPCFile, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
168  if(pBuffer != NULL)
169  {
170  OdInt8* pIpcFile = reinterpret_cast<OdInt8*>(pBuffer);
171 
172  OdUInt8Array graphics;
173  ::oddbEndProxyGraphics( m_pWd, graphics );
174 
175  OdUInt32 n = kGraphics;
176  memcpy(pIpcFile, &n, sizeof(n));
177  pIpcFile += sizeof(n);
178 
179  n = graphics.size();
180  memcpy(pIpcFile, &n, sizeof(n));
181  pIpcFile += sizeof(n);
182 
183  memcpy(pIpcFile, graphics.getPtr(), graphics.size());
184 
185  ::UnmapViewOfFile(pBuffer);
186  }
187  ::CloseHandle(hIPCFile);
188  }
189 
190  ::SetEvent(hBufferWritten);
191  }
192  ::CloseHandle(hBufferWritten);
193  ::CloseHandle(hBufferProcessed);
194  m_pWd.release();
195  }
196 
197 #endif //_WIN32
198 }
199 
200 inline void
202 {
203 #if defined(_WIN32) && !defined(_WINRT) && !defined(_WIN32_WCE)
204 
205  HANDLE hBufferWritten = ::OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, L"OdaRemoteGeometryBufferWrittenEvent");
206  HANDLE hBufferProcessed = ::OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, L"OdaRemoteGeometryBufferProcessedEvent");
207 
208  if(hBufferWritten != NULL && hBufferProcessed != NULL)
209  {
210  ::WaitForSingleObject(hBufferProcessed, INFINITE);
211 
212  HANDLE hIPCFile = ::OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, L"OdaRemoteGeometryViewerIPCBuffer");
213  if(hIPCFile != NULL)
214  {
215  void* pBuffer = ::MapViewOfFile(hIPCFile, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
216  if(pBuffer != NULL)
217  {
218  OdInt8* pIpcFile = reinterpret_cast<OdInt8*>(pBuffer);
219 
221  memcpy(pIpcFile, &n, sizeof(n));
222  pIpcFile += sizeof(n);
223 
224  n = (s.getLength() + 1) * 2;
225  memcpy(pIpcFile, &n, sizeof(n));
226 
227  pIpcFile += sizeof(n);
228  memcpy(pIpcFile, s.c_str(), n);
229 
230  ::UnmapViewOfFile(pBuffer);
231  }
232  ::CloseHandle(hIPCFile);
233  }
234 
235  ::SetEvent(hBufferWritten);
236  }
237 
238  ::CloseHandle(hBufferWritten);
239  ::CloseHandle(hBufferProcessed);
240 
241 #endif //_WIN32
242 }
243 
244 #include "TD_PackPop.h"
245 
246 #endif //_ODREMOTEGEOMPROXY_INCLUDED_
OdRemoteGeomProxyAutoBlock
Definition: RemoteGeomProxy.h:99
OdString
Definition: OdString.h:95
OdDbDatabase
Definition: DbDatabase.h:421
NULL
#define NULL
Definition: GsProperties.h:177
OdRemoteGeomProxy::traits
OdGiSubEntityTraits & traits()
Definition: RemoteGeomProxy.h:145
OdRemoteGeomProxy::begin
void begin()
Definition: RemoteGeomProxy.h:130
OdRemoteGeomProxy::m_pDb
OdDbDatabasePtr m_pDb
Definition: RemoteGeomProxy.h:49
OdRemoteGeomProxy::setDatabase
void setDatabase(OdDbDatabase *pDb)
Definition: RemoteGeomProxy.h:126
OdArray< OdUInt8, OdMemoryAllocator< OdUInt8 > >
TD_PackPop.h
OdRemoteGeomProxy
Definition: RemoteGeomProxy.h:47
OdRemoteGeomProxy::wDraw
OdGiWorldDraw & wDraw()
Definition: RemoteGeomProxy.h:135
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdArray::getPtr
const T * getPtr() const
Definition: OdArray.h:1102
OD_T
#define OD_T(x)
Definition: OdPlatformSettings.h:714
OdRemoteGeomProxy::~OdRemoteGeomProxy
~OdRemoteGeomProxy()
Definition: RemoteGeomProxy.h:121
OdSmartPtr::release
void release()
Definition: SmartPtr.h:264
OdRemoteGeomProxy::sendStringToExecute
void sendStringToExecute(const OdString &s)
Definition: RemoteGeomProxy.h:201
GiWorldDraw.h
OdSmartPtr< OdGiWorldDraw >
OdRemoteGeomProxy::Opcode
Opcode
Definition: RemoteGeomProxy.h:54
DbDatabase.h
OdGiCommonDraw::subEntityTraits
virtual OdGiSubEntityTraits & subEntityTraits() const =0
OdRemoteGeomProxy::wGeom
OdGiWorldGeometry & wGeom()
Definition: RemoteGeomProxy.h:140
OdArray::size
size_type size() const
Definition: OdArray.h:893
OdSmartPtr::get
const T * get() const
Definition: SmartPtr.h:326
OdRemoteGeomProxy::OdRemoteGeomProxy
OdRemoteGeomProxy()
Definition: RemoteGeomProxy.h:116
OdGiWorldGeometry
Definition: GiWorldGeometry.h:51
OdRemoteGeomProxyAutoBlock::~OdRemoteGeomProxyAutoBlock
~OdRemoteGeomProxyAutoBlock()
Definition: RemoteGeomProxy.h:108
oddbEndProxyGraphics
TOOLKIT_EXPORT void oddbEndProxyGraphics(OdGiWorldDraw *pWdSaver, OdUInt8Array &graphics)
OdRemoteGeomProxyAutoBlock::OdRemoteGeomProxyAutoBlock
OdRemoteGeomProxyAutoBlock(OdRemoteGeomProxy &proxy)
Definition: RemoteGeomProxy.h:103
TD_PackPush.h
OdGiSubEntityTraits
Definition: Gi.h:94
OdInt8
signed char OdInt8
Definition: OdPlatformSettings.h:755
OdGiWorldDraw
Definition: GiWorldDraw.h:44
SmartPtr.h
OdGiWorldDraw::geometry
virtual OdGiWorldGeometry & geometry() const =0
UInt8Array.h
OdRemoteGeomProxy::kGraphics
@ kGraphics
Definition: RemoteGeomProxy.h:55
OdRemoteGeomProxy::kStringToExecute
@ kStringToExecute
Definition: RemoteGeomProxy.h:56
TOOLKIT_EXPORT
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
oddbBeginProxyGraphics
TOOLKIT_EXPORT OdSmartPtr< OdGiWorldDraw > oddbBeginProxyGraphics(OdDbDatabase *pDbCtx)
GeCircArc2d.h
OdString::c_str
const OdChar * c_str() const
Definition: OdString.h:200
OdRemoteGeomProxy::end
void end()
Definition: RemoteGeomProxy.h:150
OdRemoteGeomProxy::m_pWd
OdSmartPtr< OdGiWorldDraw > m_pWd
Definition: RemoteGeomProxy.h:50
OdString::getLength
int getLength() const
Definition: OdString.h:130