CFx SDK Documentation  2023 SP0
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_
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
#define NULL
Definition: GsProperties.h:177
#define OD_T(x)
unsigned int OdUInt32
signed char OdInt8
TOOLKIT_EXPORT OdSmartPtr< OdGiWorldDraw > oddbBeginProxyGraphics(OdDbDatabase *pDbCtx)
TOOLKIT_EXPORT void oddbEndProxyGraphics(OdGiWorldDraw *pWdSaver, OdUInt8Array &graphics)
size_type size() const
Definition: OdArray.h:893
const T * getPtr() const
Definition: OdArray.h:1102
virtual OdGiSubEntityTraits & subEntityTraits() const =0
virtual OdGiWorldGeometry & geometry() const =0
OdRemoteGeomProxyAutoBlock(OdRemoteGeomProxy &proxy)
OdGiSubEntityTraits & traits()
void sendStringToExecute(const OdString &s)
OdDbDatabasePtr m_pDb
void setDatabase(OdDbDatabase *pDb)
OdGiWorldGeometry & wGeom()
OdGiWorldDraw & wDraw()
OdSmartPtr< OdGiWorldDraw > m_pWd
void release()
Definition: SmartPtr.h:264
const T * get() const
Definition: SmartPtr.h:326
const OdChar * c_str() const
Definition: OdString.h:200
int getLength() const
Definition: OdString.h:130