zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
 
#ifndef _FdField_h_Included_
#define _FdField_h_Included_
 
#include "RxObject.h"
#include "RxDictionary.h"
#include "DbField.h"
 
class OdDbField;
class OdDbEvalVariant;
class OdFieldValue;
class OdFdFieldEngineImpl;
class OdFdFieldResult;
class OdDbDatabase;
 
#include "TD_PackPush.h"
 
/** \details
  This class is an abstract base class that defines the field evaluator interface.
  \remarks
  Applications implement evaluators for fields by deriving from this class. 
  The evaluator object instantiated from this class is obtained from the field 
  evaluator loader using the evaluator ID stored in the field. An evaluator class 
  can be implemented for each type of field, or a single evaluator class can support 
  multiple types of fields.
  <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldEvaluator : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldEvaluator);
 
  /** \details
    Returns the evaluator IDs supported by this evaluator.
    \remarks
    This function can return more than one evaluator ID if the evaluator 
    supports multiple IDs. If more than one ID is returned, the evaluator 
    IDs are separated by commas.
  */
  virtual const OdString evaluatorId() const = 0;
  /** \details
    Returns the evaluator ID for the specified field code.
    \remarks
    This version will be called to find an evaluator for a field code 
    that does not have an evaluator ID set. Implementations of this function 
    should examine the field code. If the field code is recognized by the evaluator 
    and can be handled by it, then this function should return the evaluator ID. 
    \param pField [in]  Input field for which to return an evaluator ID 
  */
  virtual const OdString evaluatorId(OdDbField* pField) const = 0;
  /** \details
    This function is called by the
    field framework calls this method to initialize a new field.
    \remarks
    This method is called after setting a field code in the field and 
    before compile() is called. The evaluator can change the default 
    options that are set in the field when it is created. This method 
    will be called only once for a field. 
    \param pField [in]  Input field to initialize 
  */
  virtual OdResult initialize(OdDbField* pField) const = 0; 
 
//    The field framework calls this method to compile a field when the field code is changed.   
  
  /** \details
    This function is called by the frame framework
    to compile a field when the field code is changed.
    \remarks
    The evaluator can do any parsing of the field code here and store the parsed data in the 
    field. This method will be called only when the field code is changed, unlike evaluate(), 
    which is called whenever the field needs to be evaluated.
    \param pField [in]  Input field to compile 
    \param pDb [in]  Input database pointer 
    \param pResult [in]  Input field result object to set the compilation status 
  */
  virtual OdResult compile(OdDbField* pField, 
    OdDbDatabase* pDb,
    OdFdFieldResult* pResult) const = 0;
 
//  The field framework calls this method to evaluate a field whenever the field needs 
//    to be evaluated.
 
  /** \details
    This function is called by the field framework when the field needs to be evaluated.
    \remarks
    A field will be evaluated only when the evaluation option set in 
    the field matches the context in which the field evaluation is invoked. For example,
    if a field option is set to evaluate only manually, then it will be evaluated only 
    when the user updates the specific field or all fields in the drawing manually.
 
    The evaluator should evaluate the field and set the evaluated value using 
    OdFdFieldResult::setFieldValue() and the error status using OdFdFieldResult::setEvaluationStatus() 
    in the passed result object, which in turn will set them in the field object.
 
    The passed database pointer may be null if the field is not database resident and a 
    database could not be obtained in the current context. If the field evaluation requires 
    a database, then this method can set the evaluation error status in the field result object 
    and return an error. 
 
    If the evaluation fails for any reason, the previously cached result in the field object can 
    be left intact and used as the field value. Alternatively, the cached result can be deleted 
    and substituted with an error string (for example, "#ERR"), which will be displayed as field 
    value.
 
    \param pField [in]  Input field to evaluate 
    \param nContext [in]  Input context in which the field is evaluated; this context flag is passed to the evaluator and can be one of the predefined OdDbField::EvalContext enum flags or a user-defined context flag 
    \param pDb [in]  Input database pointer, which can be null if a database could not be obtained in the current context 
    \param pResult [in]  Input field result object to set the evaluation result and status 
  */
  virtual OdResult evaluate(OdDbField* pField, 
    int nContext, 
    OdDbDatabase* pDb, 
    OdFdFieldResult* pResult) const = 0;
 
//      The field framework calls this method when a field is queried 
//      to get the evaluated field value as a string. The evaluator can 
 
  /** \details
      This function is called by the field framework
      when a field is queried to get the evaluated field value as a string. 
      \remarks
      The evaluator can 
      implement this method to support custom formatting of field values. 
      If the evaluator does not implement this method, the standard data types will 
      be formatted using default formats.
 
      \param pField [in]  Field whose value is to be formatted 
      \param pszValue [out]  Pointer to the string that is the field value formatted as a string
  */
  virtual OdResult format(OdDbField* pField, OdString& pszValue) const = 0;
};
 
typedef OdSmartPtr<OdFdFieldEvaluator> OdFdFieldEvaluatorPtr;
 
/** \details
  This class is used to load the evaluators required for evaluating fields. 
  \remarks
  This class acts as the interface between the field framework and the applications 
  that implement evaluators. An application that implements evaluators should derive 
  from this class and register an object of this class with the field engine when 
  the application is loaded. The registered loader is used by the engine to obtain 
  the evaluator object. Only one loader object is required for an application and 
  it can support multiple evaluators. The loader objects are maintained globally and 
  are used by all open documents.
  <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldEvaluatorLoader : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldEvaluatorLoader);
 
  /** \details
    The field engine calls this method to get the evaluator using the evaluator ID 
    and uses the evaluator to evaluate the field. 
    \param pszEvalId [in]  Input evaluator ID for which the evaluator is required 
  */
  virtual OdFdFieldEvaluator* getEvaluator(
    const OdString& pszEvalId) = 0;
 
  /** \details
    Finds an evaluator for a field that does not have an evaluator ID. 
    \param pField [in]  Input field for which to find an evaluator 
    \param pszEvalId [out]  Output pointer to receive the evaluator ID 
  */
  virtual OdFdFieldEvaluator * findEvaluator(
    OdDbField* pField, 
    OdString& pszEvalId) = 0;
};
 
/** \details
  This class is used to get notifications when fields in a database are evaluated.
  <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldReactor : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldReactor);
 
  /** \details
    Notification function called before one or more fields in a database are evaluated.
    \param nContext [in]  Input evaluation context 
    \param pDb [in]  Input pointer to database in which the fields are evaluated 
  */
  virtual void beginEvaluateFields(
    int nContext, 
    OdDbDatabase* pDb);
  
  /** \details
    Notification function called after one or more fields in a database are evaluated.
    \param nContext [in]  Input evaluation context 
    \param pDb [in]  Input pointer to database in which the fields are evaluated 
  */
  virtual void endEvaluateFields(
    int nContext, 
    OdDbDatabase* pDb);
};
 
typedef OdArray<OdFdFieldReactor*> FieldReactors;
 
/** \details
  This class manages the evaluation of fields. 
  \note
  The field engine is a global one-per-session object. 
 
  The field evaluators should register their loader with 
  the engine during application startup
  <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldEngine : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldEngine);
  virtual ~OdFdFieldEngine(){}
  /** \details
    Registers the evaluator loader with the engine. 
    \remarks The engine searches the registered
    evaluator loaders to find the appropriate evaluator for evaluating fields. Field 
    evaluators should register the evaluator loader with the field engine during application
    startup.
    \param pLoader [in]  Input evaluator loader to register 
  */
  virtual void registerEvaluatorLoader(OdFdFieldEvaluatorLoader* pLoader) = 0;
 
  /** \details
    Unregisters the evaluator loader from the engine. 
    \remarks
    Field evaluator modules 
    should unregister the evaluator loader when the module is unloaded, 
    before deleting the loader object.
    \param pLoader [in]  Input evaluator loader to unregister 
  */
  virtual void unregisterEvaluatorLoader(OdFdFieldEvaluatorLoader* pLoader) = 0;
 
  /** \details
    Returns the number of registered field evaluator loaders.
  */
  virtual int evaluatorLoaderCount() const = 0;
 
  /** \details
    Returns the field evaluator loader at the specified index.
    \remarks
    This function can be used with evaluatorLoaderCount() to 
    enumerate the evaluator loaders.
    \param inputIndex [in]  Input index for which to get the field evaluator loader; the index is zero based and should be less than the number of registered evaluator loaders.
  */
  virtual OdFdFieldEvaluatorLoader * getEvaluatorLoader(int inputIndex) = 0;
 
  /** \details
    Returns the field evaluator for the specified evaluator ID.
    \remarks
    Returns null if a field evaluator could not be found for the evaluator ID.
    \param pszEvalId [in]  Input evaluator ID for which to find the field evaluator 
  */
  virtual OdFdFieldEvaluator * getEvaluator (
    const OdString& pszEvalId) = 0;
 
  /** \details
    Returns an an evaluator for the specified field from the set of registered evaluators
    if the field does not have an evaluator ID. 
    \param pField [in]  Input field for which to find an evaluator 
    \param pszEvalId [out]  Output pointer to receive the evaluator ID 
    \remarks
    Returns the field evaluator for the specified field, or 
    null if a field evaluator could not be found.
 
  */
  virtual OdFdFieldEvaluator * findEvaluator(
    OdDbField* pField,
    OdString& pszEvalId) = 0;
 
  /** \details
    Adds the field reactor to the field framework.
    \param pReactor [in]  Input pointer to the reactor to be added 
  */
  virtual void addFieldReactor(OdFdFieldReactor* pReactor) = 0;
  
  /** \details
    Removes the field reactor from the field framework.
    \param pReactor [in] Input pointer to field reactor to remove 
  */
  virtual void removeFieldReactor(OdFdFieldReactor* pReactor) = 0;
};
 
typedef OdSmartPtr<OdFdFieldEngine> OdFdFieldEnginePtr;
#define ODFD_FIELD_ENGINE             OD_T("FieldEngine")
/** \details
  Returns the pointer to the field engine. There is only one field engine object per session.
*/
TOOLKIT_EXPORT OdFdFieldEnginePtr oddbGetFieldEngine();
 
/** \details
  This class is used by the evaluators to set the evaluation status and 
  evaluation result in the field. 
  \remarks
  This object is passed to the evaluators 
  during compilation and evaluation. This object cannot be instantiated.
  <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldResult : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldResult);
  OdFdFieldResult();
  
  /** \details
    Sets the evaluation result in the field.
    \param pValue [in]  Input evaluation to set in the field.
    \remarks
    If pValue is null,the cached evaluation is deleted. 
  */
  virtual void setFieldValue(const OdFieldValue* pValue) = 0;
  
  /** \details
    Sets the evaluation status in the field.
    \param errorStatus [in]  Error status
    \param errorCode [in]  Extended error code or zero for success
    \param errorMessage [in]  Error message
  */
  virtual void setEvaluationStatus(OdDbField::EvalStatus errorStatus, int errorCode = 0, const OdString& errorMessage = OdString()) = 0;
};
 
/** \details
    This abstract class is the Field Engine Protocol Extension class.
    Its purpose is to provide services necessary for fields evaluation implemented at the host application level.
    <group Other_Classes>
*/
class TOOLKIT_EXPORT OdFdFieldEnginePE : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdFdFieldEnginePE);
  /** \details
    Retrieves sheet set property value.
 
    \param propValue [out]  result property value
    \param compName [in]  component name
    \param propName [in]  property name
    \param pDb [in]  database
 
    Returns 'true' if the property was successfully retrieved to 'propValue', otherwise returns 'false'.
  */
  virtual bool getSheetSetProperty(OdString& propValue, const OdString& compName, const OdString& propName, OdDbDatabase* pDb) = 0;
 
  /** \details
    Parses property string of ObjProp field code retrieving object id and property type.
 
    \param prop [in]  property string: "Object(%<\_ObjId XXX>%).PropName"
    \param pDb [in]  database
    \param objId [out]  object id
    \param propName [out]  property name
 
    Returns 'true' on success, otherwise returns 'false'.
  */
  virtual bool parseObjProp(const OdString& prop, OdDbDatabase* pDb, OdDbObjectId& objId, OdString& propName) = 0;
 
  /** \details
    Retrieves object property value.
 
    \param propName [in]  property name
    \param objId [in]  object
    \param result [out]  result
 
    Returns 'true' on success, otherwise returns 'false'.
  */
  virtual bool getObjPropValue(const OdString& propName, const OdDbObjectId& objId, OdFdFieldResult& result) = 0;
 
  /** \details
    Retrieves the current database of the host application.
    The purpose of the function is to allow using the current database's properties when processing NDBRO fields.
 
    Returns pointer to the current OdDbDatabase object.
  */
  virtual OdDbDatabase* getCurrentDb() = 0;
 
  /** \details
    Returns the name of the file associated with this database object.
    Differs from the current behavior of OdDbDatabase::getFilename(),
    which returns autobackup filename, because OdDbDatabase::writeFile()
    always sets m_currentFileName.
 
    \param pDb [in]  database
  */
  virtual OdString getFileName(OdDbDatabase* pDb) = 0;
 
  /** \details
    Retrieves value of lisp variable.
 
    \param lispVar [in]  lisp variable name
    \param fValue [out]  field value where the result is stored
  */
  virtual void getLispVariable(const OdString& lispVar, OdFieldValue& fValue) = 0;
};
 
typedef OdSmartPtr<OdFdFieldEnginePE> OdFdFieldEnginePEPtr;
 
/** \details
    Evaluates fields in database.
    \param pDb [in]  Pointer to the database for which fields are to be evaluated
    \param nContext [in]  Input context in which the field is evaluated, which can be a predefined *OdDbField::EvalContext* enum flag or a user-defined context flag; this context flag is passed to the evaluator
    \param objIds [in]  Input array of object IDs of objects, whose fields are to be evaluated. If this is not null only, fields will be evaluated only for these objects.
    \param pFieldsToEvaluate [in]  Input array of object IDs of fields to be evaluated. If this is not null only these fields in the specified objects will be evaluated. If this is null all the fields in the specified objects will be evaluated.
    \param pszEvaluatorId [in]  Input evaluator ID. If this is not null only the fields matching this evaluator ID will be evaluated. If this is null all the fields in the specified objects will be evaluated. 
    \param nEvalFlag [in]  Input one or more OdFd::EvalFields option flags
    \param pNumFound [out]  Output pointer to store the number of fields found; can be null if this information is not required 
    \param pNumEvaluated [out]  Output pointer to store the number of fields evaluated; can be null if this information is not required 
*/
TOOLKIT_EXPORT OdResult oddbEvaluateFields( 
  OdDbDatabase* pDb,
  int nContext,
  const OdDbObjectIdArray* objIds = 0, 
  const OdDbObjectIdArray* pFieldsToEvaluate = 0,
  const OdString& pszEvaluatorId = OdString(),
  OdFd::EvalFields nEvalFlag = OdFd::kEvalRecursive,
  int* pNumFound = 0,
  int* pNumEvaluated = 0);
 
 
#include "TD_PackPop.h"
 
#endif //_FdField_h_Included_