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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2015, 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-2015 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
// stdafx.cpp : source file that includes just the standard includes
// OpenCAD.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
 
#include "stdafx.h"
 
// #ifdef _TOOLKIT_IN_DLL_
 
 
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2015, 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-2015 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
// stdafx.cpp : source file that includes just the standard includes
// OpenCAD.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
 
 
#include <map>
#include <vector>
 
std::map<int, OdDbObjectId> _mapId2Object;
std::map<int, OdDbObjectId> _mapId2ObjectText;
 
// #endif
int addHatches(const OdDbObjectId& btrId, const OdString& textName, float w,
    double x, double y, const OdDbObjectId& layerId,
    const OdDbObjectId& shxStyleId, const OdDbObjectId& ttfStyleId,
    bool bValidText) {
    /**********************************************************************/
    /* Open the BlockTableRecord                                          */
    /**********************************************************************/
    OdDbBlockTableRecordPtr bBTR = btrId.safeOpenObject(OdDb::kForWrite);
 
    OdDbDatabase* pDb = btrId.database();
 
    OdGePoint3d rightupper = pDb->getEXTMAX();
    OdGePoint3d leftBottom = pDb->getEXTMIN();
    /**********************************************************************/
    /* Get the Upper-left corner of the box and its size                  */
    /**********************************************************************/
    OdGePoint3d point;
    point.x = x;
    point.y = y;
    //  double h    = m_EntityBoxes.getHeight();
    //double w = 3000;
    double delta = w;
 
    /**********************************************************************/
    /* Create a rectangular Hatch with a circular hole                    */
    /**********************************************************************/
    OdDbHatchPtr pHatch = OdDbHatch::createObject();
    pHatch->setDatabaseDefaults(pDb);
    OdDbObjectId whiteHatchId = bBTR->appendOdDbEntity(pHatch);
 
    /**********************************************************************/
    /* Set some properties                                                */
    /**********************************************************************/
    pHatch->setAssociative(false);
    pHatch->setPattern(OdDbHatch::kPreDefined, OD_T("SOLID"));
    pHatch->setHatchStyle(OdDbHatch::kNormal);
 
    OdCmColor col1;
    if (!bValidText) {
        col1.setRGB(240, 104, 37);
    }
    else {
        col1.setRGB(37, 214, 240);
    }
    //    col1.setRGB(255, 0, 0); //±ê×¢ÑÕÉ«
    pHatch->setColor(col1);
    OdCmTransparency transparency;
    transparency.setAlphaPercent(0.7);
    pHatch->setTransparency(transparency);
 
    /**********************************************************************/
    /* Define the outer loop with an OdGePolyline2d                       */
    /**********************************************************************/
    OdGePoint2dArray vertexPts;
    OdGeDoubleArray vertexBulges;
 
    double zy = 0.8;
    double zx = 0.2;
    double zw = 1.5;
    double zh = 1;
    vertexPts.resize(7);
    vertexPts[0].set(point.x, point.y);
    vertexPts[1].set(point.x + delta * zx, point.y * zh + delta * zy);
    vertexPts[2].set(point.x + delta * zw, point.y * zh + delta * zy);
    vertexPts[3].set(point.x + delta * zw, point.y * zh + delta * zy + delta);
    vertexPts[4].set(point.x - delta * zw, point.y * zh + delta * zy + delta);
    vertexPts[5].set(point.x - delta * zw, point.y * zh + delta * zy);
    vertexPts[6].set(point.x - delta * zx, point.y * zh + delta * zy);
 
    pHatch->appendLoop(OdDbHatch::kExternal | OdDbHatch::kPolyline, vertexPts,
        vertexBulges);
 
    std::vector < OdDbObjectId > vecObjectId;
 
    vecObjectId.push_back(pHatch->objectId());
 
    OdDbHandle id1 = pHatch->handle();
    OdUInt64 nId = id1;
    _mapId2Object[nId] = pHatch->objectId();
 
    /**********************************************************************/
    /* Add a label                                                        */
    /**********************************************************************/
    OdGePoint3d position;
    position = point;
    point.y += zy * w + w * 0.5;
    point.z = 10;
    OdDbObjectId id = addTextEnt(bBTR, point, point, textName, 0.4 * w,
        OdDb::kTextMid, OdDb::kTextVertMid, layerId, shxStyleId);
 
    _mapId2ObjectText[nId] = id;
 
    return nId;
}
 
/************************************************************************/
/* Add an Image to the specified BlockTableRecord                       */
/************************************************************************/
int addImage(OdDbDatabasePtr pDb, const OdString& sImagePath, double xPos, double yPos, double width, double height, const OdString& textName, const OdDbObjectId& layerId, const OdDbObjectId& shxStyleId)
{
    OdDbBlockTableRecordPtr pRecord = pDb->getActiveLayoutBTRId().safeOpenObject(OdDb::kForWrite);
    OdDbObjectId imageDictId = OdDbRasterImageDef::createImageDictionary(pRecord->database());
    OdDbDictionaryPtr pImageDict = imageDictId.safeOpenObject(OdDb::kForWrite);
    // Create image definition
    OdDbObjectId defId;
    OdDbRasterImageDefPtr pDef = OdDbRasterImageDef::createObject();
    pDef->setSourceFileName(sImagePath);
    
    char s[MAX_PATH];
//    int i = _mapId2Object.size();
    int i = rand();
    sprintf(s, "pic__%d", i);
    defId = pImageDict->setAt(s, pDef);
    // Try to load raster image to found correct dimensions inside TD
    OdDbRasterImageDefPtr pDefLoad = OdDbRasterImageDef::cast(defId.openObject(OdDb::kForWrite));
    OdResult result = pDefLoad->load(false);
    OdGeVector2d size = pDefLoad->size();
    if(width==0){
        width = size.x;
        height = size.y;
    }
    // Create and attach raster image reference
    OdDbRasterImagePtr pRef = OdDbRasterImage::createObject();
    pRef->setDatabaseDefaults(pDb);
    pRecord->appendOdDbEntity(pRef);
 
    pRef->setImageDefId(defId);
    OdGePoint3d origin;
    OdGeVector3d u, v;
 
 
    origin.x = xPos-width/2;
    origin.y = yPos;
    origin.z = 0;
 
    
    u.set(width, 0, 0);
    v.set(0, height, 0);
 
    pRef->setOrientation(origin, u, v);
    pRef->setDisplayOpt(OdDbRasterImage::kShow, true);
    pRef->setDisplayOpt(OdDbRasterImage::kTransparent, true);
    pRef->setDisplayOpt(OdDbRasterImage::kClip, false);
    OdCmTransparency transparency;
    if (textName.getLength()) {
        transparency.setAlphaPercent(0.7);
    } else {
        transparency.setAlphaPercent(1.0);
    }
    pRef->setTransparency(transparency);
    
    //¹Ø±ÕͼƬframe
    OdDbRasterVariablesPtr pRVars = OdDbRasterVariables::openRasterVariables(pRecord->database(), OdDb::kForWrite);
    pRVars->setImageFrame(OdDbRasterVariables::kImageFrameOff);
 
 
    OdDbHandle id1 = pRef->handle();
    OdUInt64 nId = id1;
    _mapId2Object[nId] = pRef->objectId();
 
 
    /**********************************************************************/
    /* Add a label                                                        */
    /**********************************************************************/
    OdGePoint3d position;
    position = origin;
    position.x += width / 2;
    position.y += height / 1.5;
    position.z = 10;
    OdDbObjectId id = addTextEnt(pRecord, position, position, textName, 0.5 * height,
        OdDb::kTextMid, OdDb::kTextVertMid, layerId, shxStyleId);
 
    _mapId2ObjectText[nId] = id;
 
    return nId;
}
 
OdDbObjectId addLayer(OdDbDatabase* pDb, const OdString& name,
    const OdCmColor color, const OdString& linetype) {
    OdDbLayerTablePtr pLayersRead = pDb->getLayerTableId().safeOpenObject(
        OdDb::kForRead);
    OdDbSymbolTableIteratorPtr pEntIter = pLayersRead->newIterator();
    /********************************************************************/
    for (; !pEntIter->done(); pEntIter->step()) {
        /********************************************************************/
        /* Dump the Entity                                                  */
        /********************************************************************/
        OdDbLayerTableRecordPtr pEntity = pEntIter->getRecord();
        if (pEntity->getName() == name)
            return pEntity->objectId();
    }
 
    /**********************************************************************/
    /* Open the layer table                                               */
    /**********************************************************************/
    OdDbLayerTablePtr pLayers = pDb->getLayerTableId().safeOpenObject(
        OdDb::kForWrite);
 
    /**********************************************************************/
    /* Create a layer table record                                        */
    /**********************************************************************/
    OdDbLayerTableRecordPtr pLayer = OdDbLayerTableRecord::createObject();
 
    /**********************************************************************/
    /* Layer must have a name before adding it to the table.              */
    /**********************************************************************/
    pLayer->setName(name);
 
    /**********************************************************************/
    /* Set the Color.                                                     */
    /**********************************************************************/
    //    pLayer->setColorIndex(color);
    pLayer->setColor(color);
 
    /**********************************************************************/
    /* Set the Linetype.                                                  */
    /**********************************************************************/
    OdDbLinetypeTablePtr pLinetypes = pDb->getLinetypeTableId().safeOpenObject(
        OdDb::kForRead);
    OdDbObjectId linetypeId = pLinetypes->getAt(linetype);
    pLayer->setLinetypeObjectId(linetypeId);
 
    /**********************************************************************/
    /* Add the record to the table.                                       */
    /**********************************************************************/
    OdDbObjectId layerId = pLayers->add(pLayer);
 
    return layerId;
}
 
/************************************************************************/
/* Add a Text Style to the specified database                           */
/*                                                                      */
/* The symbol table and symbol table record are implicitly closed when  */
/* this function returns.                                               */
/************************************************************************/
OdDbObjectId addStyle(OdDbDatabase* pDb, const OdString& txt, const OdString& hztxt, const OdString& styleName,
    double textSize, double xScale, double priorSize, double obliquing,
    const OdString& fileName, bool isShapeFile, const OdString& ttFaceName,
    bool bold, bool italic, int charset, int pitchAndFamily)
{
    OdDbTextStyleTablePtr pLayersRead =
        pDb->getTextStyleTableId().safeOpenObject(OdDb::kForRead);
    OdDbSymbolTableIteratorPtr pEntIter = pLayersRead->newIterator();
    /********************************************************************/
    for (; !pEntIter->done(); pEntIter->step()) {
        /********************************************************************/
        /* Dump the Entity                                                  */
        /********************************************************************/
        OdDbTextStyleTableRecordPtr pEntity = pEntIter->getRecord();
        if (pEntity->getName() == styleName)
            return pEntity->objectId();
    }
 
    OdDbObjectId styleId;
 
    OdDbTextStyleTablePtr pStyles = pDb->getTextStyleTableId().safeOpenObject(
        OdDb::kForWrite);
    OdDbTextStyleTableRecordPtr pStyle =
        OdDbTextStyleTableRecord::createObject();
 
    // Name must be set before a table object is added to a table.  The
    // isShapeFile flag must also be set (if true) before adding the object
    // to the database.
    pStyle->setName(styleName);
    pStyle->setIsShapeFile(false);
 
    pStyle->setFileName(txt);
    pStyle->setBigFontFileName(hztxt);
 
    // Add the object to the table.
    styleId = pStyles->add(pStyle);
 
    // Set the remaining properties.
    pStyle->setTextSize(textSize);
    pStyle->setXScale(xScale);
    pStyle->setPriorSize(priorSize);
    pStyle->setObliquingAngle(obliquing);
    //    pStyle->setFileName(fileName);
    if (isShapeFile) {
        pStyle->setPriorSize(22.45);
    }
    if (!ttFaceName.isEmpty()) {
        pStyle->setFont(ttFaceName, bold, italic, charset, pitchAndFamily);
    }
 
    return styleId;
}
 
std::vector<OdDbObjectId> _vecObjectId;
 
void ZoomTag(OdDbDatabasePtr m_pDatabase, double revZoomScale) {
    OdDbBlockTableRecordPtr pBlockTableRecord =
        m_pDatabase->getModelSpaceId().safeOpenObject(OdDb::kForRead);
    OdGePoint3d Start, End;
    std::map<int, OdDbObjectId>::iterator iter = _mapId2Object.begin();
    while (iter != _mapId2Object.end()) {
        int key = iter->first;
        OdDbObjectId val = iter->second;
        OdDbObjectPtr oid = val.openObject(OdDb::kForWrite, false);
 
        OdDbHatchPtr hatch = OdDbHatch::cast(oid);
        if (!hatch.isNull()) {
            OdGePoint2dArray vertices;
            OdGeDoubleArray bulges;
            hatch->getLoopAt(0, vertices, bulges);
            //    writeLine(indent++, OD_T("Edges"));
            int nCnt = vertices.size();
            OdGePoint2d origin = vertices[0];
            Start.set(origin.x, origin.y, 0);
            OdGeMatrix3d tm;
            tm.setToScaling(revZoomScale, Start);
            hatch->transformBy(tm);
 
            std::map<int, OdDbObjectId>::iterator iter1 = _mapId2ObjectText.find(
                key);
            if (iter1 != _mapId2ObjectText.end()) {
                OdDbObjectId val = iter1->second;
                OdDbObjectPtr oid = val.openObject(OdDb::kForWrite, false);
 
                OdDbTextPtr text = OdDbText::cast(oid);
                if (!text.isNull()) {
                    OdGePoint3d pos = text->position();
 
                    OdGeMatrix3d tm;
                    tm.setToScaling(revZoomScale, Start);
                    text->transformBy(tm);
                }
            }
        }
 
        
 
        OdDbRasterImagePtr image = OdDbRasterImage::cast(oid);
        if (!image.isNull()) {
            OdGePoint3d origin;
            OdGeVector3d u, v;
            image->getOrientation(origin, u, v);
            origin.x += u[0] / 2;
            OdGeMatrix3d tm;
            tm.setToScaling(revZoomScale, origin);
            image->transformBy(tm);
 
            std::map<int, OdDbObjectId>::iterator iter1 = _mapId2ObjectText.find(
                key);
            if (iter1 != _mapId2ObjectText.end()) {
                OdDbObjectId val = iter1->second;
                OdDbObjectPtr oid = val.openObject(OdDb::kForWrite, false);
 
                OdDbTextPtr text = OdDbText::cast(oid);
                if (!text.isNull()) {
                    OdGePoint3d pos = text->position();
 
                    OdGeMatrix3d tm;
                    tm.setToScaling(revZoomScale, origin);
                    text->transformBy(tm);
                }
            }
        }
 
        iter++;
    }
}
 
/************************************************************************/
/* Add a text entity with the specified attributes to the specified     */
/* BlockTableRecord                                                     */
/************************************************************************/
OdDbObjectId addTextEnt(OdDbBlockTableRecord* bBTR, const OdGePoint3d& position,
    const OdGePoint3d& ap, const OdString& str, double height,
    OdDb::TextHorzMode hMode, OdDb::TextVertMode vMode,
    const OdDbObjectId& layerId, const OdDbObjectId& styleId,
    OdDbGroup* pGroup) {
    /**********************************************************************/
    /* Create the text object                                             */
    /**********************************************************************/
    OdDbTextPtr pText = OdDbText::createObject();
    pText->setDatabaseDefaults(bBTR->database());
    OdDbObjectId textId = bBTR->appendOdDbEntity(pText);
 
    // Make the text annotative
    OdDbAnnotativeObjectPEPtr(pText)->setAnnotative(pText, true);
 
    /**********************************************************************/
    /* Add the text to the specified group                                */
    /**********************************************************************/
    if (pGroup) {
        pGroup->append(textId);
    }
 
    /**********************************************************************/
    /* Set some properties                                                */
    /**********************************************************************/
    pText->setPosition(position);
    pText->setAlignmentPoint(ap);
    pText->setHeight(height);
    pText->setWidthFactor(1.0);
    pText->setTextString(str);
    pText->setHorizontalMode(hMode);
    pText->setVerticalMode(vMode);
 
    /**********************************************************************/
    /* Set the text to the specified style                                */
    /**********************************************************************/
    if (!styleId.isNull()) {
        pText->setTextStyle(styleId);
    }
    /**********************************************************************/
    /* Set the text to the specified layer                                */
    /**********************************************************************/
    if (!layerId.isNull()) {
        pText->setLayer(layerId, false);
    }
 
    return textId;
}
 
void ScreenToWorld(OdGsViewPtr pDevice, float x, float y, float out[]) {
    OdGsViewPtr pView = pDevice;
    OdGePoint3d WCSPoint(x, y, 0.0);
 
    OdGeMatrix3d screenMatrix = pView->screenMatrix();
    OdGeMatrix3d projectionMatrix = pView->projectionMatrix();
 
    WCSPoint.transformBy(
        (pView->screenMatrix() * pView->projectionMatrix()).inverse());
    WCSPoint.z = 0.0;
    WCSPoint.transformBy(OdAbstractViewPEPtr(pView)->eyeToWorld(pView));
 
    out[0] = WCSPoint.x;
    out[1] = WCSPoint.y;
    out[2] = WCSPoint.z;
}
 
void WorldToScreen(OdGsViewPtr pDevice, float x, float y, float z,
    float out[]) {
    OdGsViewPtr pView = pDevice;
    OdGePoint3d WCSPoint(x, y, z);
    OdGeMatrix3d xWorldToScr = pView->worldToDeviceMatrix();
    OdGePoint3d pt = xWorldToScr * WCSPoint;
 
    out[0] = pt.x;
    out[1] = pt.y;
}
 
int AddShape(OdDbDatabase* pDb, const OdString& txt, const OdString& hztxt, float x, float y, float fSize, const OdString& sImagePath, const OdString& sLableText, bool bValidText)
{
    OdCmColor clr;
    OdString name;
    //    clr.setRGB(255, 255, 255);
    if (bValidText){
        clr.setRGB(255, 255, 255);
        name = OD_T("JKYTextLayer");
    }
    else{
        clr.setRGB(0, 255, 0);
        name = OD_T("JKYTextLayer1");
    }
 
    OdDbObjectId odaLayerId = addLayer(pDb, name, clr, OD_T("CONTINUOUS"));
 
    OdDbObjectId shxTextStyleId = addStyle(pDb, txt, hztxt, OD_T("OdaShxStyle"), 0.0, 1.0,
        0.2, 0.0, OD_T("txt"));
 
    //int nId = addHatches(pDb->getModelSpaceId(), sLableText, 2000, x, y, odaLayerId, shxTextStyleId, shxTextStyleId, bValidText);
 
    int nId = addImage(pDb, sImagePath, x, y, fSize, fSize*0.3, sLableText, odaLayerId, shxTextStyleId);
    return nId;
}
 
void DeleteShape(OdDbDatabasePtr m_pDatabase, int nID) {
    OdDbBlockTableRecordPtr pBlockTableRecord =
        m_pDatabase->getModelSpaceId().safeOpenObject(OdDb::kForRead);
 
    if (nID > 0) {
        std::map<int, OdDbObjectId>::iterator iter = _mapId2Object.find(nID);
        if (iter != _mapId2Object.end()) {
            OdDbObjectId id = iter->second;
            OdDbObjectPtr oid = id.openObject(OdDb::kForWrite, false);
            oid->erase();
 
            _mapId2Object.erase(iter);
        }
 
        iter = _mapId2ObjectText.find(nID);
        if (iter != _mapId2ObjectText.end()) {
            OdDbObjectId id = iter->second;
            OdDbObjectPtr oid = id.openObject(OdDb::kForWrite, false);
            oid->erase();
 
            _mapId2ObjectText.erase(iter);
        }
    }
    else {
        std::map<int, OdDbObjectId>::iterator iter = _mapId2Object.begin();
        while (iter != _mapId2Object.end()) {
            DeleteShape(m_pDatabase, iter->first);
            iter++;
        }
        ClearData();
    }
}
 
int PickShapeByCursor(OdGsViewPtr pDevice, OdDbDatabasePtr m_pDatabase, float x,
    float y) {
    int nRet = 0;
    OdDbBlockTableRecordPtr pBlockTableRecord =
        m_pDatabase->getModelSpaceId().safeOpenObject(OdDb::kForRead);
    float out[3];
    ScreenToWorld(pDevice, x, y, out);
    OdGePoint3d Start, End;
    std::map<int, OdDbObjectId>::iterator iter = _mapId2Object.begin();
    while (iter != _mapId2Object.end()) {
        int key = iter->first;
        OdDbObjectId val = iter->second;
        OdDbObjectPtr oid = val.openObject(OdDb::kForRead, false);
 
        OdDbHatchPtr hatch = OdDbHatch::cast(oid);
        if (!hatch.isNull()) {
            OdGePoint2dArray vertices;
            OdGeDoubleArray bulges;
            hatch->getLoopAt(0, vertices, bulges);
            //    writeLine(indent++, OD_T("Edges"));
            int nCnt = vertices.size();
 
            float xmin = 0, ymin = 0, xmax = 0, ymax = 0;
            for (int i = 0; i < nCnt; i++) {
                if (i == 0) {
                    xmin = vertices[i].x;
                    ymin = vertices[i].y;
                    xmax = vertices[i].x;
                    ymax = vertices[i].y;
                }
                else {
                    if (xmin > vertices[i].x)
                        xmin = vertices[i].x;
                    if (ymin > vertices[i].y)
                        ymin = vertices[i].y;
                    if (xmax < vertices[i].x)
                        xmax = vertices[i].x;
                    if (ymax < vertices[i].y)
                        ymax = vertices[i].y;
                }
            }
 
            if (out[0] > xmin && out[0] < xmax && out[1] > ymin
                && out[1] < ymax) {
                nRet = key;
                break;
            }
        }
 
        OdDbRasterImagePtr image = OdDbRasterImage::cast(oid);
        if (!image.isNull()) 
        {
            float xmin = 0, ymin = 0, xmax = 0, ymax = 0;
            OdGePoint3d origin;
            OdGeVector3d u, v;
            image->getOrientation(origin, u, v);
            
            xmin = origin.x;
            ymin = origin.y;
            xmax = xmin + u[0];
            ymax = ymin + v[1];
            if (out[0] > xmin && out[0] < xmax && out[1] > ymin
                && out[1] < ymax) {
                nRet = key;
                break;
            }
        }
 
        iter++;
    }
 
    return nRet;
}
 
void ClearData() {
    _mapId2Object.clear();
    _mapId2ObjectText.clear();
}
 
 
// #endif