Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HDWGHelper.h

00001 // (C) Copyright 1996,1998 by Autodesk, Inc. 
00002 //
00003 // Permission to use, copy, modify, and distribute this software in
00004 // object code form for any purpose and without fee is hereby granted, 
00005 // provided that the above copyright notice appears in all copies and 
00006 // that both that copyright notice and the limited warranty and
00007 // restricted rights notice below appear in all supporting 
00008 // documentation.
00009 //
00010 // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
00011 // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
00012 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
00013 // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
00014 // UNINTERRUPTED OR ERROR FREE.
00015 //
00016 // Use, duplication, or disclosure by the U.S. Government is subject to 
00017 // restrictions set forth in FAR 52.227-19 (Commercial Computer
00018 // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
00019 // (Rights in Technical Data and Computer Software), as applicable.
00020 //
00021 // $Id: 4a1dd4df53be6c79ccbe3d2d050b34d006bd00db $
00022 //
00023 
00024 #ifndef HDWG_HELPER_H_
00025 #define HDWG_HELPER_H_ 1
00026 
00027 #ifdef H_PACK_8
00028 #pragma pack(push)
00029 #pragma pack(8)
00030 #endif
00031 
00032 
00033 //#include <wchar.h>
00034 #include <map>
00035 #include <vector>
00036 #include <string>
00037 
00038 #include "acgi.h"
00039 #include "hc.h"
00040 #include "HIOManager.h"
00041 #include "HTools.h"
00042 #include "HUtility.h"
00043 
00044 #include "BStream.h"
00045 #include "BOpcodeShell.h"
00046 
00047 #include "sorttab.h "
00048 
00049 #include "windows.h"
00050 #include "stdlib.h"
00051 #include "stdio.h"
00052 #include "string.h"
00053 #include "time.h"
00054 
00055 #include "dbimage.h"
00056 #include "imgdef.h"
00057 #include "imgent.h"
00058 
00059 #include "dbobjptr.h"
00060 #include "acdblmgr.h"
00061 #include "dbmleader.h"  // For AcDbMLeader
00062 #include "dblight.h"
00063 #include "dbspfilt.h"   // For Clips on blockref
00064 #include "dbole.h"
00065 #include "dbtrans.h"    // For Transaction objects
00066 
00067 
00068 
00069 #define _t(str) L##str
00070 typedef unsigned int        UINT;
00071 
00072 
00073 
00074 class HInputHandlerOptions;
00075 class HIOConnectorDWG;
00076 class HIOUtilityDWG;
00077 
00078 class AcDbMText;
00079 struct AcDbMTextFragment;
00080 class AcDbCircle;
00081 class AcDbLeader;
00082 class AcDbMLeader;
00083 class AcDbDimension;
00084 class AcDbMaterial;
00085 class AcDbPoint;
00086 class AcDbMInsertBlock;
00087 class AcDbLine;
00088 class AcDbXline;
00089 class AcDbRay;
00090 class AcDbPolygonMesh;
00091 
00092 #ifdef WIN32
00093 class AcDbTable;
00094 #endif 
00095 
00096 typedef int  BOOL;
00097 
00098 // Functions to condition strings form database to be used as segment name.
00099 void condition_string_for_segment_name(char* zString);
00100 void condition_string_for_segment_name(wchar_t* zString);
00101 void condition_string_for_user_options(char* zString);
00102 void condition_string_for_user_options(wchar_t* zString);
00103 void condition_string_for_special_characters(wchar_t* zString);
00104 
00105 // To get the rectangle from bounding box
00106 void Get_Image_Rectangle_For_Shell(AcDbRasterImage* pEnt, HPoint * Rect);
00107 // AcDbRatsterImage import Functions
00108 void InsertClipRegion(AcDbRasterImage* pEnt, BStreamFileToolkit * pBStreamtk = 0);
00109 int GetImageFileName(AcDbRasterImageDef* ImageDef, char * pFilePath, char * pImageName) ;
00110 // Camera settings in viewports
00111 int GetCameraForInitialView(HCamera &camera , AcDbViewportTableRecord* pRecord);
00113 void SetRenderMode(HInputHandlerOptions * pInputOptions, AcDbViewportTableRecord* pRecord);
00114 // text transformation matrix
00115 void GetModelingMatrixForText(float my_center[], float my_path1[], float my_norm1[], float h_matrix_trans[]);
00116 // For Stream Writing
00117 TK_Status WriteObject(BBaseOpcodeHandler * handler, BStreamFileToolkit * tk, FILE * fp, char * buffer, int size); 
00118 // For Getting Layout views and clip regions
00119 void get_layout_data(AcDbObjectId viewPortId,AcDbDatabase *pAcDbDatabase,HPoint *ClipPoint,float *matrix,int *no_ClipPoint,AcCmEntityColor* entityColor, bool * is_On);
00120 // Convert to lower case
00121 void ConverToLower(char * to_lower);
00122 // Check for file existance
00123 bool hio_dwg_check_file_exist(const wchar_t * full_filepath);
00124 // For Clips on BlockRefs
00125 BOOL insertClip(AcDbBlockReference * ref, BStreamFileToolkit * pBStreamtk = 0);
00126 // Checking for invalid entities (having large and invalid values)
00127 bool CheckForInvalidExtents(AcDbEntity * pEnt);
00128 
00129 inline void extract_matrix(AcGeMatrix3d const & in_mat, float out_mat[16])
00130 {
00131     AcGeMatrix3d trans_matrix(in_mat);
00132     trans_matrix.transposeIt();
00133     for (int i = 0; i < 4; i++)
00134     {
00135         for (int j = 0; j < 4; j++)
00136         {
00137             out_mat[4 * i + j] = (float)trans_matrix(i, j);
00138         }
00139     }
00140 }
00141 
00142 
00143 // define HIODWG_IMPORT_POINTS if you want to import the 0 dimensional entities viz. AcDbPoint etc.
00144 //#define HIODWG_IMPORT_POINTS
00145 
00146 #define HDWG_PI         ((double)3.14159265358979323846)
00147 #define HDWG_F_PI       ((float)HDWG_PI)
00148 #define H_MM_TO_POINTS  2.83465f
00149 #define H_LWDEFAULT     AcDb::kLnWt025;
00150 #define HDWG_MATERIALS_LIBRARY_SEGMENT  "DWG_MATERIALS_STYLE_LIBRARY"
00151 #define HIODWG_SCRATCH_SEGMENT          "/include library/dwg_scratch_segment"
00152 
00153 #define GetBValueFromRGBM(rgbm)      ((unsigned char)(rgbm))
00154 #define GetGValueFromRGBM(rgbm)      ((unsigned char)((unsigned long)(rgbm)>>8))
00155 #define GetRValueFromRGBM(rgbm)      ((unsigned char)((unsigned long)(rgbm)>>16))
00156 #define GetMValueFromRGBM(rgbm)      ((unsigned char)((unsigned long)(rgbm)>>24))
00157 
00158 #define countof(array)  sizeof(array)/sizeof(array[0])
00159 #define nEntNames       countof(EntityList)
00160 
00161 
00162 #define MARKER_OPCODE_START_FILL            -1
00163 #define MARKER_OPCODE_RESTART_FILL          -2
00164 #define MARKER_OPCODE_END_FILL              -3
00165 #define MARKER_OPCODE_ELLIPSE               -4
00166 #define MARKER_OPCODE_CIRCULAR_ARC          -5
00167 #define MARKER_OPCODE_INFINITE_LINE         -6
00168 #define MARKER_OPCODE_INFINITE_RAY          -7
00169 #define MARKER_OPCODE_START_CONTRAST_COLOR  -8
00170 #define MARKER_OPCODE_START_NORMAL_COLOR    -9
00171 #define MARKER_OPCODE_START_RGB_COLOR       -10
00172 #define MARKER_OPCODE_START_INDEXED_COLOR   -11
00173 #define MARKER_OPCODE_TERMINATE 0
00174 #define MARKER_OPCODE_POINT     1
00175 #define MARKER_OPCODE_LINE_2    2
00176 #define MARKER_OPCODE_LINE_3    3
00177 #define MARKER_OPCODE_LINE_4    4
00178 #define MARKER_OPCODE_LINE_5    5
00179 #define MARKER_OPCODE_LINE_6    6
00180 #define MARKER_OPCODE_LINE_7    7
00181 #define MARKER_OPCODE_LINE_8    8
00182 #define MARKER_OPCODE_LINE_9    9
00183 #define MARKER_OPCODE_LINE_10   10
00184 #define MARKER_OPCODE_LINE_11   11
00185 #define MARKER_OPCODE_LINE_12   12
00186 #define MARKER_OPCODE_LINE_13   13
00187 
00188 
00189 const char PDMODE_4[] = // a half sized vertical bar (upper half)
00190     {
00191         100, 0, 0,   
00192         MARKER_OPCODE_LINE_2,   0, 0, 
00193                                 0, 100, 
00194         MARKER_OPCODE_TERMINATE
00195     };
00196 
00197 const char PDMODE_34[] = // a circle with + sign. + spills outside the circle
00198     {
00199         100, 0, 0,   
00200         MARKER_OPCODE_LINE_2,   -100, 0, 
00201                                  100, 0, 
00202         MARKER_OPCODE_LINE_2,     0, -100, 
00203                                   0,  100, 
00204         MARKER_OPCODE_ELLIPSE,  -60, -60, 60, 60,
00205 
00206         MARKER_OPCODE_TERMINATE
00207     };
00208 
00209 const char PDMODE_35[] = // a circle with x sign. x spills outside the circle
00210     {
00211         100, 0, 0,   
00212         MARKER_OPCODE_LINE_2,   -100, -100, 
00213                                  100,  100, 
00214         MARKER_OPCODE_LINE_2,   -100,  100, 
00215                                  100, -100, 
00216         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100,
00217 
00218         MARKER_OPCODE_TERMINATE
00219     };
00220 
00221 const char PDMODE_36[] = // a circle over a half-vertical-bar
00222     {
00223         100, 0, 0,   
00224         MARKER_OPCODE_LINE_2,   0, 0, 
00225                                 0, 100, 
00226         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100,
00227 
00228         MARKER_OPCODE_TERMINATE
00229     };
00230 
00231 const char PDMODE_66[] = // a square over + sign (+ spilling out a bit)
00232     {
00233         100, 0, 0,   
00234         MARKER_OPCODE_LINE_2,   -100, 0, 
00235                                  100, 0, 
00236         MARKER_OPCODE_LINE_2,     0, -100, 
00237                                   0,  100, 
00238         MARKER_OPCODE_LINE_5,   -60, -60,   -60, 60,
00239                                  60, 60,    60, -60, -60, -60,
00240         MARKER_OPCODE_TERMINATE
00241     };
00242 
00243 const char PDMODE_68[] = // a square over half-vertical-bar
00244     {
00245         100, 0, 0,   
00246         MARKER_OPCODE_LINE_2,   0, 0, 
00247                                 0, 100, 
00248         MARKER_OPCODE_LINE_5,   -100, -100, -100, 100,
00249                                  100, 100,  100, -100,-100, -100,
00250         MARKER_OPCODE_TERMINATE
00251     };
00252 
00253 const char PDMODE_96[] = // a square and a circle over a dot
00254     {
00255         100, 0, 0,   
00256         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100, 
00257         MARKER_OPCODE_LINE_5,   -100, -100, -100, 100,
00258                                  100, 100,  100, -100,-100, -100,
00259         MARKER_OPCODE_POINT,    0, 0,
00260         MARKER_OPCODE_TERMINATE
00261     };
00262 
00263 const char PDMODE_97[] = // a square and a circle
00264     {
00265     100, 0, 0,   
00266         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100, 
00267         MARKER_OPCODE_LINE_5,   -100, -100, -100, 100,
00268                                  100, 100,  100, -100,-100, -100,
00269         MARKER_OPCODE_TERMINATE
00270     };
00271 
00272 const char PDMODE_98[] = // a square and a circle over + (spillage of +)
00273     {
00274         100, 0, 0,   
00275         MARKER_OPCODE_LINE_2,   -100, 0, 
00276                                  100, 0, 
00277         MARKER_OPCODE_LINE_2,     0, -100, 
00278                                   0,  100, 
00279         MARKER_OPCODE_LINE_5,   -60, -60,   -60, 60,
00280                                  60, 60,    60, -60, -60, -60,
00281         MARKER_OPCODE_ELLIPSE,  -60, -60, 60, 60, 
00282         MARKER_OPCODE_TERMINATE
00283     };
00284 
00285 const char PDMODE_99[] = // a square and a circle over a cross
00286     {
00287         100, 0, 0,   
00288         MARKER_OPCODE_LINE_2,   -100, -100, 
00289                                  100,  100, 
00290         MARKER_OPCODE_LINE_2,   -100,  100, 
00291                                  100, -100, 
00292         MARKER_OPCODE_LINE_5,   -100, -100, -100, 100,
00293                                  100, 100,  100, -100, -100, -100,
00294         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100, 
00295         MARKER_OPCODE_TERMINATE
00296     };
00297 
00298 const char PDMODE_100[] = // a square and a circle over a half-vertical-bar
00299     {
00300         100, 0, 0,   
00301         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100,
00302         MARKER_OPCODE_LINE_2,      0,  0, 
00303                                    0,  100, 
00304         MARKER_OPCODE_LINE_5,   -100, -100, -100, 100,
00305                                  100, 100,  100, -100, -100, -100,
00306         MARKER_OPCODE_ELLIPSE,  -100, -100, 100, 100,
00307         MARKER_OPCODE_TERMINATE
00308     };
00309 
00310 
00311 struct HIODWG_GLYPH
00312 {
00313     Adesk::Int16 iSymbolPDMODE;         // PDMODE value (Ref. to AutoCAD command reference
00314     char *pSymbolName;                  // Corresponding HOOPS marker symbol name or glyph name
00315     const char *pSymbolDefinition;      // Glyph definition array. 0 for standard HOOPS markers
00316     unsigned int nSybolDefinitionSize;  // Size of Glyph definition array. 0 for standard HOOPS markers
00317     int opcode_index;           // Corresponding opcode enum.
00318 };
00319 
00320 static HIODWG_GLYPH GlyphTable[] =
00321 {
00322     0,  ".",            0,              0,                  TKO_Marker_Dot,
00323     2,  "+",            0,              0,                  TKO_Marker_Plus,    
00324     3,  "x",            0,              0,                  TKO_Marker_X,
00325     4,  "PDMODE_4",     PDMODE_4,       countof(PDMODE_4),  -1,
00326 
00327     32, "(.)",          0,              0,                  TKO_Marker_Circle_Dot,
00328     33, "O",            0,              0,                  TKO_Marker_Circle ,
00329     34, "PDMODE_34",    PDMODE_34,      countof(PDMODE_34), -1,
00330     35, "PDMODE_35",    PDMODE_35,      countof(PDMODE_35), -1,
00331     36, "PDMODE_36",    PDMODE_36,      countof(PDMODE_36), -1,
00332 
00333     64, "[.]",          0,              0,                  TKO_Marker_Box_Dot,
00334     65, "[]",           0,              0,                  TKO_Marker_Box,
00335     66, "PDMODE_66",    PDMODE_66,      countof(PDMODE_66), -1,
00336     67, "[x]",          0,              0,                  TKO_Marker_Box_X ,
00337     68, "PDMODE_68",    PDMODE_68,      countof(PDMODE_68), -1,
00338 
00339     96,     "PDMODE_96",    PDMODE_96,  countof(PDMODE_96), -1,
00340     97,     "PDMODE_97",    PDMODE_97,  countof(PDMODE_97), -1,
00341     98,     "PDMODE_98",    PDMODE_98,  countof(PDMODE_98), -1,
00342     99,     "PDMODE_99",    PDMODE_99,  countof(PDMODE_99), -1,
00343     100,    "PDMODE_100",   PDMODE_100, countof(PDMODE_100),-1
00344 };
00345 
00346 
00347 
00348 struct ENTNAMES
00349 {
00350     const wchar_t *pName;
00351     void (* func)(AcDbEntity *);
00352 };
00353 
00354 static ENTNAMES EntityList[] =
00355 {
00356     // import explicitly
00357     L"AcDbBlockReference",               0, //0
00358     L"AcDbMInsertBlock",                    0,  //1
00359 
00360     // import both shaded & wireframe modes
00361     L"AcDbBlockTableRecord",             0,  //2                                          
00362     L"AcDb3dSolid",                      0, //3
00363     L"AcDbBody",                         0, //4
00364     L"AcDbFace",                         0, //5
00365     L"AcDbRegion",                       0, //6
00366     L"AcDbShape",                        0, //7
00367     L"AcDbSolid",                        0, //8
00368     L"AcDbFace",                         0, //9
00369     L"AcDbPolyFaceMesh",                 0, //10
00370     L"AcDbPolygonMesh",                  0, //11
00371     L"AcDbExtrudedSurface",             0,  //12
00372 
00373     // import wireframe mode only
00374     L"AcDbHatch",                       0,  //13
00375     L"AcDbMText",                       0,  //14
00376     L"AcDbText",                        0,  //15
00377     L"AcDbCurve",                       0,  //16
00378     L"AcDb2dPolyline",                  0,  //17
00379     L"AcDb3dPolyline",                  0,  //18
00380     L"AcDbArc",                         0,  //19
00381     L"AcDbCircle",                      0,  //20
00382     L"AcDbEllipse",                     0,  //21
00383     L"AcDbLeader",                      0,  //22
00384     L"AcDbLine",                        0,  //23
00385     L"AcDbPolyline",                    0,  //24
00386     L"AcDbRay",                         0,  //25
00387     L"AcDbSpline",                      0,  //26
00388     L"AcDbXline",                       0,  //27
00389     L"AcDbVertex",                      0,  //28
00390     L"AcDb2dVertex",                    0,  //29
00391     L"AcDb3dPolylineVertex",            0,  //30
00392     L"AcDbMline",                       0,  //31
00393     L"AcDbPoint",                       0,  //32
00394     L"AcDbPolyFaceMeshVertex",          0,  //33
00395     L"AcDbPolygonMeshVertex",           0,  //34
00396     L"AcDbBlockBegin",                  0,  //35
00397     L"AcDbBlockEnd",                    0,  //36
00398     L"AcDbFcf",                         0,  //37
00399     L"AcDbFrame",                       0,  //38
00400     L"AcDbOleFrame",                    0,  //39
00401     L"AcDbOle2Frame",                   0,  //40
00402     L"AcDbRasterImage",                 0,  //41
00403     L"AcDbZombieEntity",                0,  //42
00404     L"AcDbSequenceEnd",                 0,  //43
00405     L"AcDbAttribute",                   0,  //44
00406     L"AcDbTrace",                       0,  //45
00407     L"AcDbFaceRecord",                  0,  //46
00408     L"AcDbViewport",                    0,  //47
00409     L"AcDb2LineAngularDimension",       0,  //48
00410     L"AcDb3PointAngularDimension",      0,  //49
00411     L"AcDbAlignedDimension",            0,  //50
00412     L"AcDbDiametricDimension",          0,  //51
00413     L"AcDbOrdinateDimension",           0,  //52
00414     L"AcDbRadialDimension",             0,  //53
00415     L"AcDbRotatedDimension",            0,  //54
00416     L"AcDbArcDimension",                0,  //55
00417     L"AcDbDimension",                   0,  //56
00418     L"AcDbTable",                       0,  //57
00419     L"AcDbWipeout",                     0,  //58
00420     
00421     // DON'T import: things which I don't think make sense for importing to HOOPS
00422     // for example attribute definitions - they do have some visual representation
00423     // which we don't want to draw
00424     L"AcDbAttributeDefinition",         0,  //59
00425     L"AecDbSlab",                       0,  //60
00426 
00427 };
00428 
00429 
00430 // Base class DWG Importer. Implements common activities viz. ACAD database traversal etc.
00431 class HDWGImporter
00432 {
00433 public:
00434     HDWGImporter(HIOUtilityDWG* pDWGInputHandler);
00435     virtual ~HDWGImporter();
00436 
00437     // must have functions for any DWG Importers - Import DWG File or AcDbDatabase
00438     virtual bool importDWGFile(const wchar_t * FileName, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0) = 0;
00439     virtual bool importDWGDatabase(AcDbDatabase* pAcDbDatabase, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0) = 0;
00440 
00441     virtual void importAcDbMTextFragment(AcDbMTextFragment* pAcDbMTextFragment, AcDbMText* pOrigAcDbMText) = 0;
00442 
00443     virtual Adesk::Boolean import_circle(   const AcGePoint3d& pt1, 
00444                                     const AcGePoint3d& pt2, 
00445                                     const AcGePoint3d& pt3,
00446                                     AcDbEntity* pDatabaseEntity) const = 0;
00447 
00448     Adesk::Boolean import_circle(   const AcGePoint3d& center,
00449                                     const double radius,
00450                                     const AcGeVector3d& normal,
00451                                     AcDbEntity* pDatabaseEntity
00452                                     ) const;
00453 
00454     virtual Adesk::Boolean import_circular_arc( const AcGePoint3d& center,
00455                                         const double radius,
00456                                         const AcGeVector3d& normal,
00457                                         const AcGeVector3d& startVector,
00458                                         const double sweepAngle,
00459                                         const AcGiArcType arcType,
00460                                         AcDbEntity* pDatabaseEntity
00461                                         ) const = 0;
00462 
00463     virtual Adesk::Boolean import_circular_arc( const AcGePoint3d& start,
00464                                         const AcGePoint3d& point,
00465                                         const AcGePoint3d& end,
00466                                         const AcGiArcType arcType,
00467                                         AcDbEntity* pDatabaseEntity
00468                                         ) const = 0;
00469 
00470     virtual Adesk::Boolean import_polygon(  const Adesk::UInt32 nbPoints,
00471                                     const AcGePoint3d* pVertexList,
00472                                     AcDbEntity* pDatabaseEntity
00473                                     ) const = 0;
00474 
00475     virtual Adesk::Boolean import_polyline( const Adesk::UInt32 nbPoints,
00476                                     const AcGePoint3d* pVertexList,
00477                                     const AcGeVector3d* pNormal,
00478                                     Adesk::LongPtr lBaseSubEntMarker,
00479                                     AcDbEntity* pDatabaseEntity) const = 0;
00480 
00481     virtual Adesk::Boolean import_pline(const AcDbPolyline& lwBuf,
00482                                 Adesk::UInt32 fromIndex,
00483                                 Adesk::UInt32 numSegs,
00484                                 AcDbEntity* pDatabaseEntity) const = 0;
00485 
00486     Adesk::Boolean import_polypoint(const Adesk::UInt32 nbPoints,
00487                                     const AcGePoint3d* pVertexList,
00488                                     const AcGeVector3d* pNormal,
00489                                     const Adesk::LongPtr * pSubEntMarkers,
00490                                     AcDbEntity* pDatabaseEntity) const
00491     { /*TODO: Implement this function*/ return Adesk::kFalse;};
00492 
00493     virtual Adesk::Boolean import_mesh( const Adesk::UInt32 rows,
00494                                 const Adesk::UInt32 columns,
00495                                 const AcGePoint3d* pVertexList,
00496                                 const AcGiEdgeData* pEdgeData,
00497                                 const AcGiFaceData* pFaceData,
00498                                 const AcGiVertexData* pVertexData,
00499                                 const bool bAutoGenerateNormals,
00500                                 AcDbEntity* pDatabaseEntity
00501                                 ) const = 0;
00502 
00503     virtual Adesk::Boolean import_shell(const Adesk::UInt32 nbVertex,
00504                                 const AcGePoint3d* pVertexList,
00505                                 const Adesk::UInt32 faceListSize,
00506                                 const Adesk::Int32* pFaceList,
00507                                 const AcGiEdgeData* pEdgeData,
00508                                 const AcGiFaceData* pFaceData ,
00509                                 const AcGiVertexData* pVertexData,
00510                                 const struct resbuf* pResBuf,
00511                                 const bool bAutoGenerateNormals,
00512                                 AcDbEntity* pDatabaseEntity
00513                                 ) const = 0;
00514 
00515     virtual Adesk::Boolean import_text( const AcGePoint3d& position,
00516                                 const AcGeVector3d& normal,
00517                                 const AcGeVector3d& direction,
00518                                 const double height,
00519                                 const double width,
00520                                 const double oblique,
00521                                 const ACHAR* pMsg,
00522                                 AcDbEntity* pDatabaseEntity
00523                                 ) const = 0;
00524 
00525     virtual Adesk::Boolean  import_text(    const AcGePoint3d& position,
00526                                     const AcGeVector3d& normal,
00527                                     const AcGeVector3d& direction,
00528                                     const ACHAR* pMsg,
00529                                     const Adesk::LongPtr length,
00530                                     const Adesk::Boolean raw,
00531                                     const AcGiTextStyle &pTextStyle,
00532                                     AcDbEntity* pDatabaseEntity
00533                                     ) const=0 ;
00534 
00535     virtual void pushModelTransform(AcGeMatrix3d const & xMat) = 0;
00536     virtual void popModelTransform() = 0;
00537 
00538 
00539     double get_deviation() const { return m_Deviation; }
00540 
00541     void set_deviation( double dev ) { m_Deviation = dev; }
00542 
00543     int get_num_isolines() const { return m_numIsolines; }
00544 
00545     void setIs2dEntity(bool val)  { m_bIs2DEntity = val;}
00546 
00547     HInputHandlerOptions const * GetInputOptions() const { return m_pInputOptions; }
00548 
00549 protected:
00550 
00551     void importAcDbPoint(AcDbPoint *pAcDbPoint);
00552     void importAcDbMText(AcDbMText* pAcDbMText);
00553     void importAcDbCircle(AcDbCircle* pAcDbCircle);
00554     void importAcDbMaterial(AcDbMaterial *pAcDbMaterial);
00555 
00556     bool shouldOverrideMaterial(AcDbMaterial * pAcDbMaterial);
00557     bool hasValidRGBValues(AcCmEntityColor const * in_color, float & out_red, float & out_green, float & out_blue) const;
00558     
00559     virtual void importXdata(AcDbEntity *pEnt)=0;
00560     virtual void importXdata(resbuf *pBuf) = 0;
00561     void import_hyperlinks(AcDbEntity *pEnt);
00562     virtual void attachDWGHandle(AcDbEntity *pEnt)=0;
00563 
00564     virtual bool get_entity_rgb(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord, float& red, float& green, float& blue, bool& is_by_block, bool for_blk_ref=false);
00565     virtual void get_entity_transparency(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord, int &alpha_value, bool& is_by_block );
00566     virtual void get_entity_visibility(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord, bool& is_visible );
00567     virtual void get_entity_line_weight(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord, float& ret_line_weight, bool& is_by_block);
00568 
00569     HIOUtilityDWG* m_pDWGInputHandler;
00570     HIOConnectorDWG* m_pConnectivityInfo;
00571     HC_KEY  m_modelKey;
00572     wchar_t*    m_pDWGTextureDirectory;
00573     bool    m_bDrawWireframe;
00574     bool    m_bIs3D;
00575     double  m_Deviation;
00576     bool    m_bImportXData;
00577     bool    m_bImportWireframeForBrep;
00578     int     m_numIsolines;
00579     struct vlist_s* m_listRegAppNames;
00580     struct vlist_s* m_listEntityType;
00581     bool m_bAttachDWGHandles;
00582     bool m_bAmIsolidHatch;
00583 
00584     HInputHandlerOptions * m_pInputOptions;
00585 
00586     float m_wmin[3];
00587     float m_wmax[3];
00588     int m_nLine_count;
00589     int m_nPoint_count;
00590     int m_nCircle_count;
00591     int m_nArc_count;
00592     int m_nSolid_count;
00593     int m_nSolid3D_count;
00594     int m_nGroup_count;
00595     int m_nPloyLine_count;
00596     int m_nShell_count;
00597     int m_nText_count;
00598     int m_nPloygon_count;
00599 
00600     wchar_t const * m_fileName;
00601     std::map<int, wchar_t*> layer_record;
00602     std::map<int, wchar_t*> group_record;
00603     std::map<int, wchar_t*> entity_record;
00604     std::map<int, wchar_t*> block_ref_record;
00605     std::vector<AcDbObjectId> m_VpIdCount;
00606     int m_BlockRefIndex;
00607     struct vlist_s* m_listDWGLayouts;
00608     bool m_bImportAllLayouts;
00609     bool m_bCleanVpList;
00610     bool m_bIgnoreOffEntity;
00611     double m_dGlobalScaleFactor;
00612     bool    m_bIs2DEntity;
00613     bool m_bIsSHXFont;
00614     bool m_bDWGInsertMeshesAsShells;
00615     bool m_bDisableDWGDrawOrder;
00616 
00617     struct dimensionAttributes
00618     {
00619         dimensionAttributes()
00620         {
00621             r = -1;
00622             g = -1;
00623             b = -1;
00624             isVisible = false;
00625         }
00626         dimensionAttributes(float red, float green, float blue, bool visibility)
00627         {
00628             r = red;
00629             g = green;
00630             b = blue;
00631             isVisible = visibility;
00632         }
00633         float r, g, b;
00634         bool isVisible;
00635     };
00636 
00637     mutable std::map<std::wstring, std::string> m_fontmap;
00638     void populate_fontmap() const;
00639 
00640     /* dimensionData and m_dimensions are used to regenerate missing dimensions at runtime */
00641     struct dimensionData
00642     {
00643         dimensionData(HC_KEY dKey, HC_KEY sKey, AcDbHandle h, AcDbBlockTableRecord * btr)
00644         {
00645             destinationKey = dKey;
00646             sourceKey = sKey;
00647             dimensionHandle = h;
00648             dimensionBTR = btr;
00649             dAtt;
00650         }
00651 
00652         dimensionAttributes dAtt;
00653         HC_KEY destinationKey;                      // key to the segment where the dimension will be inserted
00654         HC_KEY sourceKey;                           // key to the segment containing the recomputed dimension BTR
00655         AcDbHandle dimensionHandle;                 // handle of the dimension object
00656         AcDbBlockTableRecord * dimensionBTR;        // recomputed dimension BTR
00657     };
00658     std::vector<dimensionData> m_dimensions;
00659     virtual void recomputeAndImportDimensions(std::vector<dimensionData> * dimensionVector) = 0;
00660 };
00661 
00662 // DWG import implementation for HIOUtilityDWG interface
00663 class HDWG_3dgsImporter : public HDWGImporter
00664 {
00665 public:
00666     HDWG_3dgsImporter(HIOUtilityDWG* pDWGInputHandler) : HDWGImporter(pDWGInputHandler)
00667     {
00668         m_CurrentLayoutName = 0;
00669     };
00670     ~HDWG_3dgsImporter(){;};
00671 
00672     virtual void recomputeAndImportDimensions(std::vector<dimensionData> * dimensionVector);
00673 
00674     virtual bool importDWGFile(const wchar_t * FileName, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0);
00675     virtual bool importDWGDatabase(AcDbDatabase* pAcDbDatabase, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0);
00676 
00677     virtual void importAcDbMTextFragment(AcDbMTextFragment* pAcDbMTextFragment, AcDbMText* pOrigAcDbMText);
00678     virtual void importAcDbDimension(AcDbDimension* pAcDbDimension);
00679 
00680     Adesk::Boolean import_circle(   const AcGePoint3d& pt1, 
00681                                     const AcGePoint3d& pt2, 
00682                                     const AcGePoint3d& pt3,
00683                                     AcDbEntity* pDatabaseEntity) const;
00684 
00685     Adesk::Boolean import_circle(   const AcGePoint3d& center,
00686                                     const double radius,
00687                                     const AcGeVector3d& normal,
00688                                     AcDbEntity* pDatabaseEntity
00689                                     ) const;
00690 
00691     Adesk::Boolean import_circular_arc( const AcGePoint3d& center,
00692                                         const double radius,
00693                                         const AcGeVector3d& normal,
00694                                         const AcGeVector3d& startVector,
00695                                         const double sweepAngle,
00696                                         const AcGiArcType arcType,
00697                                         AcDbEntity* pDatabaseEntity
00698                                         ) const;
00699 
00700     Adesk::Boolean import_circular_arc( const AcGePoint3d& start,
00701                                         const AcGePoint3d& point,
00702                                         const AcGePoint3d& end,
00703                                         const AcGiArcType arcType,
00704                                         AcDbEntity* pDatabaseEntity
00705                                         ) const;
00706 
00707     Adesk::Boolean import_polygon(  const Adesk::UInt32 nbPoints,
00708                                     const AcGePoint3d* pVertexList,
00709                                     AcDbEntity* pDatabaseEntity
00710                                     ) const;
00711     HC_KEY HDWG_3dgsImporter::extrude_pline(AcGePoint3dArray dwgPoints, AcGeVector3d normal, double line_thickness) const;
00712     Adesk::Boolean import_polyline( const Adesk::UInt32 nbPoints,
00713                                     const AcGePoint3d* pVertexList,
00714                                     const AcGeVector3d* pNormal,
00715                                     Adesk::LongPtr lBaseSubEntMarker,
00716                                     AcDbEntity* pDatabaseEntity) const;
00717 
00718     void import_extruded_pline(const AcDbPolyline& lwBuf, int i, AcDbEntity* pDatabaseEntity) const;
00719     void import_exploded_pline(const AcDbPolyline& lwBuf, int i, AcDbEntity* pDatabaseEntity) const;
00720     void import_fancy_pline(const AcDbPolyline& lwBuf, AcDbEntity* pDatabaseEntity) const;
00721 
00722     Adesk::Boolean import_pline(const AcDbPolyline& lwBuf,
00723                                 Adesk::UInt32 fromIndex,
00724                                 Adesk::UInt32 numSegs,
00725                                 AcDbEntity* pDatabaseEntity) const;
00726     HC_KEY extrude_elliptical_arc (
00727                     const double *ofst,
00728                     const double thickness,
00729                     const double *p0,
00730                     const double *p1,
00731                     const double *p2, 
00732                     double start,
00733                     double end) const;
00734 
00735     Adesk::Boolean import_polypoint(const Adesk::UInt32 nbPoints,
00736                                     const AcGePoint3d* pVertexList,
00737                                     const AcGeVector3d* pNormal,
00738                                     const Adesk::LongPtr * pSubEntMarkers,
00739                                     AcDbEntity* pDatabaseEntity) const
00740                                     { /*TODO: Implement this function*/ return Adesk::kFalse;};
00741 
00742     Adesk::Boolean import_mesh( const Adesk::UInt32 rows,
00743                                 const Adesk::UInt32 columns,
00744                                 const AcGePoint3d* pVertexList,
00745                                 const AcGiEdgeData* pEdgeData,
00746                                 const AcGiFaceData* pFaceData,
00747                                 const AcGiVertexData* pVertexData,
00748                                 const bool bAutoGenerateNormals,
00749                                 AcDbEntity* pDatabaseEntity
00750                                 ) const;
00751 
00752     Adesk::Boolean import_shell(const Adesk::UInt32 nbVertex,
00753                                 const AcGePoint3d* pVertexList,
00754                                 const Adesk::UInt32 faceListSize,
00755                                 const Adesk::Int32* pFaceList,
00756                                 const AcGiEdgeData* pEdgeData,
00757                                 const AcGiFaceData* pFaceData ,
00758                                 const AcGiVertexData* pVertexData,
00759                                 const struct resbuf* pResBuf,
00760                                 const bool bAutoGenerateNormals,
00761                                 AcDbEntity* pDatabaseEntity
00762                                 ) const;
00763 
00764     Adesk::Boolean import_text( const AcGePoint3d& position,
00765                                 const AcGeVector3d& normal,
00766                                 const AcGeVector3d& direction,
00767                                 const double height,
00768                                 const double width,
00769                                 const double oblique,
00770                                 const ACHAR* pMsg,
00771                                 AcDbEntity* pDatabaseEntity
00772                                 ) const;
00773 
00774     Adesk::Boolean  import_text(    const AcGePoint3d& position,
00775                                     const AcGeVector3d& normal,
00776                                     const AcGeVector3d& direction,
00777                                     const ACHAR* pMsg,
00778                                     const Adesk::LongPtr length,
00779                                     const Adesk::Boolean raw,
00780                                     const AcGiTextStyle &pTextStyle,
00781                                     AcDbEntity* pDatabaseEntity
00782                                     ) const;
00783     
00784     HC_KEY import_text( float my_center[], 
00785                         float my_path1[], 
00786                         float my_norm1[], 
00787                         wchar_t const * text,
00788                         const char* alignment 
00789                         ) const; // deprecated 
00790     
00791     HC_KEY apply_transforms_and_insert_text(float my_center[], 
00792                                             float my_path1[], 
00793                                             float my_norm1[], 
00794                                             wchar_t const * text,
00795                                             const char* alignment 
00796                                             ) const;
00797 
00798     void pushModelTransform(AcGeMatrix3d const & xMat);
00799     void popModelTransform();
00800 
00801 private:
00802 
00803     void importAcDbEntity(AcDbEntity* pEnt, HC_KEY parent_seg = INVALID_KEY, bool for_blk_ref=false);
00804     void importAcDbEntity(AcDbEntity *pEnt, const bool& draw_shaded, 
00805                           HC_KEY parent_seg = INVALID_KEY, bool for_blk_ref=false);
00806 
00807     void importAcDbBlockReference(AcDbBlockReference *pAcDbBlockReference, HC_KEY parent_seg = INVALID_KEY, int mib_col=0, int mib_row=0);
00808     void importAcDbMInsertBlock(AcDbMInsertBlock *pAcDbMInsertBlock,HC_KEY parent_seg);
00809 
00810     void importAcDbPoint(AcDbPoint *pAcDbPoint);
00811     void importAcDbCircle(AcDbCircle* pAcDbCircle);
00812     void importAcDbMaterial(AcDbMaterial *pAcDbMaterial, AcGiMapper mapper);
00813     void importLBGEData();
00814     void importAcDbLine(AcDbLine *pAcDbLine);
00815     void importAcDb3dPolyline(AcDb3dPolyline *pAcDbPolyline);
00816     void importAcDbXline(AcDbXline* pXline);
00817     void importAcDbRay(AcDbRay* pRay);
00818     void importAcDbViewport(AcDbViewport* pViewport);
00819     void importAcDbRasterImage(AcDbRasterImage* pEnt);
00820     void importAcDbMLeader(AcDbMLeader* pEnt);
00821     void importAcDbLight(AcDbLight* pEnt);
00822     #ifdef WIN32
00823     void importAcDbTable(AcDbTable* pAcDbTable);
00824     #endif 
00825     void importXdata(AcDbEntity *pEnt); 
00826     void importBlockTableRecord(AcDbBlockTableRecord* pRecord);
00827     void attachDWGHandle(AcDbEntity *pEnt);
00828 
00829     void get_entity_material_style(AcDbEntity* pEnt, const AcDbLayerTableRecord *pLayerTableRecord, HC_KEY& style_key);
00830 
00831     virtual void importXdata(resbuf *pBuf);
00832     void import_hyperlinks(AcDbEntity *pEnt);
00833     void set_marker_settings(const Adesk::Int16 db_pdmode, const double db_pdsize );
00834 
00835     void import_entity_linetype(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord);
00836     void import_entity_linetype(const AcDbObjectId& pLinetypeId, double linetype_scale);
00837     void import_layout(AcDbDatabase *pAcDbDatabase);
00838     void update_layout_list(AcDbDatabase* pAcDbDatabase);
00839     void set_initial_view_for_model_space(AcDbDatabase* pAcDbDatabase);
00840     void InsertMaskRegion(AcDbRasterImage* pEnt);
00841 
00842 
00843     HC_KEY GetBlockTableRecordSegmentFromId(const AcDbObjectId& blockTableRecordID, bool& isNew);
00844     HC_KEY GetBlockTableRecordSegmentForEntity(AcDbEntity *pEnt);
00845     
00846 
00847     wchar_t* m_CurrentLayoutName;
00848     std::map<void * , HC_KEY> m_Segments_map;
00849     std::map<void * , HC_KEY>::const_iterator m_keymap_ieterator;
00850 
00851     // For progress bar
00852     int m_nTotalEntities;
00853     int m_nCurrentEntityCount;
00854     void GetNoOfEntitiesForProgressBar(AcDbDatabase* pAcDbDatabase);
00855 
00856     friend class HDrawOrderHandler;
00857 
00858 };
00859 
00860 class HDWG_BStreamImporter : public HDWGImporter
00861 {
00862 public:
00863     HDWG_BStreamImporter(HIOUtilityDWG* pDWGInputHandler, bool is_xref);
00864     ~HDWG_BStreamImporter();
00865 
00866     virtual void recomputeAndImportDimensions(std::vector<dimensionData> * dimensionVector);
00867 
00869     // Bstream Toolkit 
00870     BStreamFileToolkit *m_pBStreamtk;
00871     char *m_pBStreamBuffer;
00872     int m_nBStreamBuffSize;
00873     int m_nBStreamBuffCount;
00874     FILE *m_pHSFFile;
00875     struct vhash_s * m_vhash_StyleSegName_IsPresentFlag;
00876     struct vhash_s * m_vhash_SegName_IsPresentFlag;
00878 
00879     virtual bool importDWGFile(const wchar_t * FileName, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0);
00880     virtual bool importXRefs(AcDbDatabase* pHostDb, HC_KEY modelKey, HInputHandlerOptions * pInputOptions);
00881     virtual bool importDWGDatabase(AcDbDatabase* pAcDbDatabase, HC_KEY modelKey, HInputHandlerOptions * pInputOptions = 0);
00882 
00883     virtual void  importAcDbMTextFragment(AcDbMTextFragment* pAcDbMTextFragment, AcDbMText* pOrigAcDbMText);
00884     virtual void importAcDbDimension(AcDbDimension* pAcDbDimension, dimensionAttributes dimAtt);
00885     void import_exploded_pline(const AcDbPolyline& lwBuf, int i, AcDbEntity* pDatabaseEntity) const;
00886     void import_extruded_pline(const AcDbPolyline& lwBuf, int i, AcDbEntity* pDatabaseEntity) const;
00887     void import_fancy_pline(const AcDbPolyline& lwBuf, AcDbEntity* pDatabaseEntity) const;
00888     void extrude_pline(AcGePoint3dArray dwgPoints, AcGeVector3d normal, double line_thickness) const;
00889 
00890     Adesk::Boolean  import_circle(  const AcGePoint3d& pt1, 
00891         const AcGePoint3d& pt2, 
00892         const AcGePoint3d& pt3,
00893         AcDbEntity* pDatabaseEntity) const;
00894 
00895     Adesk::Boolean  import_circle(  const AcGePoint3d& center,
00896         const double radius,
00897         const AcGeVector3d& normal,
00898         AcDbEntity* pDatabaseEntity
00899         ) const;
00900 
00901     Adesk::Boolean  import_circular_arc(    const AcGePoint3d& center,
00902         const double radius,
00903         const AcGeVector3d& normal,
00904         const AcGeVector3d& startVector,
00905         const double sweepAngle,
00906         const AcGiArcType arcType,
00907         AcDbEntity* pDatabaseEntity
00908         ) const;
00909 
00910     Adesk::Boolean  import_circular_arc(    const AcGePoint3d& start,
00911         const AcGePoint3d& point,
00912         const AcGePoint3d& end,
00913         const AcGiArcType arcType,
00914         AcDbEntity* pDatabaseEntity
00915         ) const;
00916 
00917     Adesk::Boolean import_polygon(  const Adesk::UInt32 nbPoints,
00918         const AcGePoint3d* pVertexList,
00919         AcDbEntity* pDatabaseEntity
00920         ) const;
00921 
00922     Adesk::Boolean  import_polyline(    const Adesk::UInt32 nbPoints,
00923         const AcGePoint3d* pVertexList,
00924         const AcGeVector3d* pNormal,
00925         Adesk::LongPtr lBaseSubEntMarker,
00926         AcDbEntity* pDatabaseEntity) const;
00927 
00928     Adesk::Boolean  import_pline(const AcDbPolyline& lwBuf,
00929         Adesk::UInt32 fromIndex,
00930         Adesk::UInt32 numSegs,
00931         AcDbEntity* pDatabaseEntity) const;
00932 
00933     Adesk::Boolean import_polypoint(const Adesk::UInt32 nbPoints,
00934                                     const AcGePoint3d* pVertexList,
00935                                     const AcGeVector3d* pNormal,
00936                                     const Adesk::LongPtr * pSubEntMarkers,
00937                                     AcDbEntity* pDatabaseEntity) const
00938                                     { /*TODO: Implement this function*/ return Adesk::kFalse;};
00939 
00940     Adesk::Boolean  import_mesh(    const Adesk::UInt32 rows,
00941         const Adesk::UInt32 columns,
00942         const AcGePoint3d* pVertexList,
00943         const AcGiEdgeData* pEdgeData,
00944         const AcGiFaceData* pFaceData,
00945         const AcGiVertexData* pVertexData,
00946         const bool bAutoGenerateNormals,
00947         AcDbEntity* pDatabaseEntity
00948         ) const;
00949 
00950     Adesk::Boolean  import_shell(const Adesk::UInt32 nbVertex,
00951         const AcGePoint3d* pVertexList,
00952         const Adesk::UInt32 faceListSize,
00953         const Adesk::Int32* pFaceList,
00954         const AcGiEdgeData* pEdgeData,
00955         const AcGiFaceData* pFaceData ,
00956         const AcGiVertexData* pVertexData,
00957         const struct resbuf* pResBuf,
00958         const bool bAutoGenerateNormals,
00959         AcDbEntity* pDatabaseEntity
00960         ) const;
00961 
00962     Adesk::Boolean  import_text( const AcGePoint3d& position,
00963         const AcGeVector3d& normal,
00964         const AcGeVector3d& direction,
00965         const double height,
00966         const double width,
00967         const double oblique,
00968         const ACHAR* pMsg,
00969         AcDbEntity* pDatabaseEntity
00970         ) const;
00971 
00972     Adesk::Boolean  import_text(    const AcGePoint3d& position,
00973         const AcGeVector3d& normal,
00974         const AcGeVector3d& direction,
00975         const ACHAR* pMsg,
00976         const Adesk::LongPtr length,
00977         const Adesk::Boolean raw,
00978         const AcGiTextStyle &pTextStyle,
00979         AcDbEntity* pDatabaseEntity
00980         ) const;
00981 
00982     HC_KEY apply_transforms_and_insert_text(float my_center[], 
00983                                             float my_path1[], 
00984                                             float my_norm1[], 
00985                                             wchar_t const * text,
00986                                             const int alignment) const;
00987 
00988     void pushModelTransform(AcGeMatrix3d const & xMat);
00989     void popModelTransform();
00990 
00991     inline BOOL GetConnectivityCompression()            { return bConnectivityCompression; };
00992     inline void SetConnectivityCompression(BOOL val)            { bConnectivityCompression = val; }
00993     inline BOOL GetVertexCompression()          { return bVertexCompression; }
00994     inline void SetVertexCompression(BOOL val)          { bVertexCompression = val; }
00995     inline BOOL GetNormalCompression()          { return bNormalCompression; }
00996     inline void SetNormalCompression(BOOL val)          { bNormalCompression = val; }
00997     inline BOOL GetImageCompression()           { return bImageCompression; }
00998     inline void SetImageCompression(BOOL val)           { bImageCompression = val; }
00999     inline int  GetVertexCompressionBits()          { return m_VertexCompressionBits; }
01000     inline void SetVertexCompressionBits(int val)           { m_VertexCompressionBits = val; }
01001     inline int  GetNormalCompressionBits()          { return m_NormalCompressionBits; }
01002     inline void SetNormalCompressionBits(int val)           { m_NormalCompressionBits = val; }
01003     inline int  GetImageCompressionValue()          { return m_ImageCompressionValue; }
01004     inline void SetImageCompressionValue(int val)           { m_ImageCompressionValue = val; }
01005 
01006 
01007 protected:
01008 
01009     void  importAcDbEntity(AcDbEntity* pEnt, TK_Open_Segment* parent_seg = NULL, bool for_blk_ref=false, dimensionAttributes * dAtt = 0);
01010     void  importAcDbEntity(AcDbEntity *pEnt, const bool& draw_shaded, int entityType, 
01011                            TK_Open_Segment* parent_seg = NULL, bool for_blk_ref=false, dimensionAttributes * dAtt = 0);
01012 
01013 
01014     void  importBlockTable(AcDbBlockTable* pBlockTable);
01015     void importAcDbMInsertBlock(AcDbMInsertBlock *pAcDbMInsertBlock,TK_Open_Segment * Open_seg_handler);
01016     //void  importAcDbBlockReference(AcDbBlockReference *pAcDbBlockReference, HC_KEY parent_seg = INVALID_KEY);
01017     void  importAcDbBlockReference(AcDbBlockReference *pAcDbBlockReference, TK_Open_Segment* Open_seg_handler = NULL,
01018                                                             int mib_col = 0 , int mib_row = 0);
01019 
01020     void importAcDbPoint(AcDbPoint *pAcDbPoint);
01021     void  importAcDbCircle(AcDbCircle* pAcDbCircle);
01022     void  importAcDbMaterial(AcDbMaterial *pAcDbMaterial, AcGiMapper mapper);
01023     void importLBGEData();
01024     void importAcDbLine(AcDbLine *pAcDbLine);
01025     void importAcDbXline(AcDbXline* pXline);
01026     void importAcDb3dPolyline(AcDb3dPolyline *pAcDbPolyline);
01027     void importAcDbRay(AcDbRay* pRay);
01028     void importBlockTableRecord(AcDbBlockTableRecord* pRecord, dimensionData * dData = 0);
01029     void importAcDbViewport(AcDbViewport* pViewport);
01030     void importAcDbRasterImage(AcDbRasterImage* pEnt);
01031     void importAcDbMLeader(AcDbMLeader* pEnt);
01032     void importAcDbLight(AcDbLight* pEnt);
01033     #ifdef WIN32
01034     void importAcDbTable(AcDbTable* pAcDbTable);
01035     #endif 
01036 
01037     void importXdata(AcDbEntity *pEnt);
01038     void attachDWGHandle(AcDbEntity *pEnt);
01039     void  get_entity_material_style(AcDbEntity* pEnt, const AcDbLayerTableRecord *pLayerTableRecord, TK_Open_Segment* &parent_seg);
01040     TK_Open_Segment*  GetBlockTableRecordSegmentFromId(const AcDbObjectId& blockTableRecordID, bool& isNew);
01041     TK_Open_Segment*  GetBlockTableRecordSegmentForEntity(AcDbEntity *pEnt);
01042 
01043     //void bstream_CreateWireframeCircleWithEllipse(const HPoint &x1, const HPoint &x2, const HPoint &x3 );
01044 
01045     virtual void importXdata(resbuf *pBuf);
01046     void  import_hyperlinks(AcDbEntity *pEnt);
01047     void set_marker_settings(const Adesk::Int16 db_pdmode,const double db_pdsize );
01048     void import_entity_linetype(AcDbEntity *pEnt, const AcDbLayerTableRecord *pLayerTableRecord);
01049     void import_entity_linetype(const AcDbObjectId& pLinetypeId, double linetype_scale);
01050     void InsertMaskRegion(AcDbRasterImage* pEnt);
01051     void import_layout(AcDbDatabase *pAcDbDatabase);
01052     void update_layout_list(AcDbDatabase* pAcDbDatabase);
01053     void set_initial_view_for_model_space(AcDbDatabase* pAcDbDatabase);
01054 
01055     BOOL bConnectivityCompression;
01056     BOOL bVertexCompression;
01057     BOOL bNormalCompression;
01058     BOOL bImageCompression;
01059     int m_VertexCompressionBits;
01060     int m_NormalCompressionBits;
01061     int m_ImageCompressionValue;
01062     bool m_bMergeEntityShells;
01063     time_t  m_mtImportStart;
01064     wchar_t * m_pFileName;
01065     bool    m_bAmIXref;
01066     bool m_bScratchSegOpen;
01067     wchar_t *m_pXref_hsf_path;
01068     mutable bool m_bShellWithFaceColor;
01069 
01070     
01071     private:
01072     // small fuctions for opening/ closing segments, visibility, heuristics, 
01073     // unicode/user opts settings, etc.
01074     // Functions to reduce code size - perform TK operations
01075     int STREAM_Open_Segment(TK_Open_Segment* open_seg_handler, const char * segname) const;
01076     int STREAM_Open_Segment(const char * segname) const;
01077     int STREAM_Close_Segment() const;
01078     int STREAM_Set_Visibility(TKO_Geometry_Bits Geom_Bit, bool ifOn) const;
01079     int STREAM_Set_Heuristics(TKO_Heuristic_Bits Heuristic_Bit) const;
01080     int STREAM_Write_Object(BBaseOpcodeHandler * handler) const;
01081     static struct _stat m_MasterHsfFileTime;
01082 
01083     std::map<void * , const char *> m_Segments_map;
01084     std::map<void * ,const char *>::const_iterator m_iterator_segmap;
01085 
01086     friend class HDrawOrderHandler;
01087 };
01088 
01089 // Custom worldDraw object is sent in a call to the 
01090 // entitiy's worldDraw function.  The entity will then
01091 // end up calling the worldGeometry class's shell function.
01092 // In this case, the HAcGiWorldGeometry's shell member
01093 // function will be called.
01094 class HAcGiWorldDraw : public AcGiWorldDraw 
01095 {
01096 public:
01097 
01098     ACRX_DECLARE_MEMBERS(HAcGiWorldDraw);
01099 
01100     HAcGiWorldDraw(HDWGImporter* pDWGImporter, AcDbEntity* pAcDbEntity);
01101     virtual ~HAcGiWorldDraw();
01102 
01103     virtual AcGiRegenType           regenType() const;
01104     virtual Adesk::Boolean          regenAbort() const;
01105     virtual AcGiSubEntityTraits&    subEntityTraits() const;
01106     virtual AcGiGeometry *          rawGeometry() const;
01107     virtual AcGiWorldGeometry&      geometry() const;
01108     virtual Adesk::Boolean          isDragging() const;
01109     virtual double                  deviation(const AcGiDeviationType, const AcGePoint3d&) const;
01110     virtual Adesk::UInt32           numberOfIsolines() const;   
01111     virtual AcGiContext *           context();
01112 
01113     void                            setDeviation(double);
01114     void                            setRegenType(const AcGiRegenType&);
01115 
01116     HDWGImporter*                   GetHDWGImporter() const;
01117     AcDbEntity*                     GetCurrentEntity() const;
01118 
01119 private:
01120 
01121     AcGiSubEntityTraits*    mpSubEntityTraits;
01122     AcGiWorldGeometry*      mpWorldGeometry;
01123     AcGiContext*            mpContext;
01124     AcGiRegenType           mRegenType;
01125 
01126     HDWGImporter*           m_pDWGImporter;
01127     AcDbEntity*             m_pAcDbEntity;
01128 };
01129 
01130 // AcGiContext abstracts out the commonality between 
01131 // AcGiViewportDraw and AcGiWorldDraw. This allows you 
01132 // to code graphics routines in terms of AcGiContext that 
01133 // will work in either case. To maintain their original signatures,
01134 // AcGiWorldDraw and AcGiViewportDraw now derive from AcGiContext.
01135 // Only the database member function is implemented.  
01136 class HAcGiContext : public AcGiContext
01137 {
01138 public:
01139 
01140     ACRX_DECLARE_MEMBERS(HAcGiContext);
01141     HAcGiContext();
01142     virtual ~HAcGiContext();
01143 
01144     Adesk::Boolean          isPsOut() const;
01145     Adesk::Boolean          isPlotGeneration() const;
01146     AcDbDatabase *          database() const;
01147     bool                    isBoundaryClipping() const;
01148 
01149 };
01150 
01151 // This class contains the view independent, model coordinate,
01152 // 3D geometry methods for our custom world geometry class. 
01153 class HAcGiWorldGeometry: public AcGiWorldGeometry 
01154 { 
01155 public:
01156 
01157     ACRX_DECLARE_MEMBERS(HAcGiWorldGeometry);
01158 
01159     HAcGiWorldGeometry(HAcGiWorldDraw* pWorldDraw);
01160     ~HAcGiWorldGeometry();
01161 
01162     virtual Adesk::Boolean  draw(AcGiDrawable*) const;
01163 
01164     virtual Adesk::Boolean  circle  (const AcGePoint3d& center,
01165                                     const double radius,
01166                                     const AcGeVector3d& normal
01167                                     ) const;
01168 
01169     virtual Adesk::Boolean  circle (const AcGePoint3d& pt1,
01170                                     const AcGePoint3d& pt2,
01171                                     const AcGePoint3d& pt3
01172                                     ) const;
01173 
01174     virtual Adesk::Boolean  circularArc(const AcGePoint3d& center,
01175                                         const double radius,
01176                                         const AcGeVector3d& normal,
01177                                         const AcGeVector3d& startVector,
01178                                         const double sweepAngle,
01179                                         const AcGiArcType arcType = kAcGiArcSimple
01180                                         ) const;
01181 
01182     virtual Adesk::Boolean  circularArc(const AcGePoint3d& start,
01183                                         const AcGePoint3d& point,
01184                                         const AcGePoint3d& end,
01185                                         const AcGiArcType arcType = kAcGiArcSimple
01186                                         ) const;
01187       
01188     virtual Adesk::Boolean  polyline    (const Adesk::UInt32 nbPoints,
01189                                         const AcGePoint3d* pVertexList,
01190                                         const AcGeVector3d* pNormal = NULL,
01191                                         Adesk::LongPtr lBaseSubEntMarker = -1) const;
01192 
01193     virtual Adesk::Boolean  polyline(const AcGiPolyline& polylineObj) const ;
01194 
01195     virtual  Adesk::Boolean  polyPolyline (Adesk::UInt32 nbPolylines,
01196                                               const AcGiPolyline* pPolylines) const;            
01197     virtual  Adesk::Boolean  polyPolygon(const Adesk::UInt32 numPolygonIndices,
01198                                         const Adesk::UInt32* numPolygonPositions,
01199                                         const AcGePoint3d* polygonPositions,
01200                                         const Adesk::UInt32* numPolygonPoints,
01201                                         const AcGePoint3d* polygonPoints,
01202                                         const AcCmEntityColor* outlineColors = NULL,
01203                                         const AcGiLineType* outlineTypes = NULL,
01204                                         const AcCmEntityColor* fillColors = NULL,
01205                                         const AcCmTransparency* fillOpacities = NULL) const ;
01206     virtual  Adesk::Boolean  image(const AcGiImageBGRA32& imageSource,
01207                                       const AcGePoint3d& position,
01208                                       const AcGeVector3d& u, //orientation and magnitude of width
01209                                       const AcGeVector3d& v, //orientation and magnitude of height
01210                                       TransparencyMode transparencyMode
01211                                       ) const ;
01212     virtual  Adesk::Boolean  rowOfDots(int count,
01213                               const AcGePoint3d&     start,
01214                               const AcGeVector3d&     step
01215                              ) const ;
01216     virtual  Adesk::Boolean  ellipticalArc(const AcGePoint3d&         center,
01217                                       const AcGeVector3d&        normal,
01218                                       double                     majorAxisLength,
01219                                       double                     minorAxisLength,
01220                                       double                     startDegreeInRads,
01221                                       double                     endDegreeInRads,
01222                                       double                     tiltDegreeInRads,
01223                                       AcGiArcType                arcType
01224                                       ) const ;
01225 
01226     virtual Adesk::Boolean polypoint(const Adesk::UInt32 nbPoints,
01227                                        const AcGePoint3d* pVertexList,
01228                                        const AcGeVector3d* pNormal = NULL,
01229                                        const Adesk::LongPtr * pSubEntMarkers = NULL) const;
01230 
01231     virtual Adesk::Boolean  polygon(const Adesk::UInt32 nbPoints,
01232                                     const AcGePoint3d* pVertexList
01233                                     ) const;
01234 
01235     virtual Adesk::Boolean  mesh   (const Adesk::UInt32 rows,
01236                                     const Adesk::UInt32 columns,
01237                                     const AcGePoint3d* pVertexList,
01238                                     const AcGiEdgeData* pEdgeData = NULL,
01239                                     const AcGiFaceData* pFaceData = NULL,
01240                                     const AcGiVertexData* pVertexData = NULL,
01241                                     const bool bAutoGenerateNormals = true
01242                                     ) const;
01243 
01244     virtual Adesk::Boolean  shell(const Adesk::UInt32 nbVertex,
01245                                  const AcGePoint3d* pVertexList,
01246                                  const Adesk::UInt32 faceListSize,
01247                                  const Adesk::Int32* pFaceList,
01248                                  const AcGiEdgeData* pEdgeData = NULL,
01249                                  const AcGiFaceData* pFaceData = NULL,
01250                                  const AcGiVertexData* pVertexData = NULL,
01251                                  const struct resbuf* pResBuf = NULL,
01252                                  const bool bAutoGenerateNormals = true
01253                                  ) const;
01254     
01255       
01256     virtual Adesk::Boolean  text    (const AcGePoint3d& position,
01257                                     const AcGeVector3d& normal,
01258                                     const AcGeVector3d& direction,
01259                                     const double height,
01260                                     const double width,
01261                                     const double oblique,
01262                                     const ACHAR* pMsg
01263                                     ) const;
01264 
01265     virtual Adesk::Boolean  text(const AcGePoint3d& position,
01266                                 const AcGeVector3d& normal,
01267                                 const AcGeVector3d& direction,
01268                                 const ACHAR* pMsg,
01269                                 const Adesk::Int32 length,
01270                                 const Adesk::Boolean raw,
01271                                 const AcGiTextStyle &pTextStyle
01272                                 ) const;
01273       
01274 
01275     virtual Adesk::Boolean  xline  (const AcGePoint3d& one_xline_point,
01276                                     const AcGePoint3d& a_different_xline_point
01277                                     ) const;
01278 
01279     virtual Adesk::Boolean  ray(const AcGePoint3d& rays_starting_point,
01280                                 const AcGePoint3d& a_different_ray_point
01281                                 ) const;
01282 
01283     virtual Adesk::Boolean  pline(const AcDbPolyline& lwBuf,
01284                                   Adesk::UInt32 fromIndex = 0,
01285                                   Adesk::UInt32 numSegs = 0
01286                                   ) const;
01287 
01288     virtual void getModelToWorldTransform(AcGeMatrix3d &pMatrix) const;
01289     virtual void getWorldToModelTransform(AcGeMatrix3d &pMatrix) const;
01290     virtual void setExtents(AcGePoint3d *pNewExtents) const;
01291 
01292     virtual Adesk::Boolean pushModelTransform(const AcGeVector3d & vNormal);// Uses arbitrary Axis algorythm
01293     virtual Adesk::Boolean pushModelTransform(const AcGeMatrix3d & xMat);
01294     virtual Adesk::Boolean popModelTransform();
01295 
01296     virtual Adesk::Boolean  pushClipBoundary(AcGiClipBoundary * pBoundary);
01297     virtual void            popClipBoundary();
01298     virtual AcGeMatrix3d pushPositionTransform (AcGiPositionTransformBehavior behavior, const AcGePoint3d& offset); 
01299     virtual AcGeMatrix3d pushPositionTransform (AcGiPositionTransformBehavior behavior, const AcGePoint2d& offset); 
01300     virtual AcGeMatrix3d pushScaleTransform (AcGiScaleTransformBehavior behavior, const AcGePoint3d& extents);
01301     virtual AcGeMatrix3d pushScaleTransform (AcGiScaleTransformBehavior behavior, const AcGePoint2d& extents);
01302     virtual AcGeMatrix3d pushOrientationTransform (AcGiOrientationTransformBehavior behavior);
01303 
01304 private:
01305 
01306     // Back pointer stored to the WorldDraw object.  This class
01307     // uses it to store the ShellData when the shell member
01308     // function is called.
01309     HAcGiWorldDraw* m_pHAcGiWorldDraw;
01310     unsigned int m_uiOpenSegmentCount;
01311 };
01312 
01313 
01314 // This class applies attributes to subsequently drawn AcGi geometry
01315 // primitives.
01316 class HAcGiSubEntityTraits: public AcGiSubEntityTraits 
01317 { 
01318 public:
01319 
01320     ACRX_DECLARE_MEMBERS(HAcGiSubEntityTraits);
01321 
01322     HAcGiSubEntityTraits();
01323     ~HAcGiSubEntityTraits();
01324 
01325     virtual void setColor(const Adesk::UInt16 color);
01326     virtual void setTrueColor(const AcCmEntityColor& color);
01327     virtual void setLayer(const AcDbObjectId layerId);
01328     virtual void setLineType(const AcDbObjectId linetypeId);
01329     virtual void setSelectionMarker(const Adesk::LongPtr markerId);
01330     virtual void setFillType(const AcGiFillType fillType);
01331     virtual void setLineWeight(const AcDb::LineWeight lw);
01332     virtual void setLineTypeScale(double dScale = 1.0);
01333 
01334 
01335     virtual Adesk::UInt16       color() const;
01336     virtual AcCmEntityColor     trueColor() const;
01337     virtual AcDbObjectId        layerId() const;
01338     virtual AcDbObjectId        lineTypeId() const;
01339     virtual AcGiFillType        fillType() const;
01340     virtual AcDb::LineWeight    lineWeight() const;
01341     virtual double              lineTypeScale() const;
01342 
01343     virtual void   setThickness(double dThickness);
01344     virtual double thickness() const;
01345 
01346 private:
01347 
01348     Adesk::UInt16   mColorIndex;
01349     AcCmEntityColor mTrueColor;
01350     AcDbObjectId    mLayerId;
01351     AcDbObjectId    mLinetypeId;
01352     Adesk::LongPtr  mMarkerId;
01353     AcGiFillType    mFillType;  
01354     AcDb::LineWeight  mLineWeight;
01355     double          mLineTypeScale;
01356     double          mThickness;
01357 };
01358 
01359 // Some entities (particularly custom entities from AEC etc.) are viewport entities 
01360 // They don't have any visual reprentation in world (worldDraw fails), but they 
01361 // have a specific representation in viewport. Hence we are deriving from ViewportDraw
01362 //  --- SK 17 mar 09
01363 
01364 class HAcGiViewportDraw : public AcGiViewportDraw
01365 {
01366 public:
01367     ACRX_DECLARE_MEMBERS(HAcGiViewportDraw);
01368     HAcGiViewportDraw(HDWGImporter* pDWGImporter, AcDbEntity* pAcDbEntity);
01369     ~HAcGiViewportDraw();
01370     
01371     virtual AcGiViewport&        viewport() const;
01372     virtual AcGiViewportGeometry& geometry() const;
01373     virtual Adesk::UInt32        sequenceNumber() const;
01374     virtual Adesk::Boolean       isValidId(const Adesk::ULongPtr acgiId) const;
01375     virtual AcDbObjectId         viewportObjectId() const;
01376 
01377     virtual AcGiRegenType           regenType() const ;
01378     virtual Adesk::Boolean          regenAbort() const {return Adesk::kFalse;};
01379     virtual AcGiSubEntityTraits&    subEntityTraits() const ;
01380     virtual AcGiGeometry *   rawGeometry() const ;
01381     virtual Adesk::Boolean          isDragging() const {return Adesk::kFalse;};
01382 
01383     // This function operates against the current active viewport
01384     //
01385     virtual double                deviation(const AcGiDeviationType, const AcGePoint3d&) const {return 0.00;};
01386     virtual Adesk::UInt32           numberOfIsolines() const {return 0;};
01387     
01388     virtual AcGiContext *      context();
01389 
01390     HDWGImporter*                   GetHDWGImporter() const;
01391     AcDbEntity*                     GetCurrentEntity() const;
01392 
01393 private:
01394     AcGiViewport* mpVp;
01395     AcGiViewportGeometry* mpVpGeometry;
01396     AcDbObjectId mpObjId;
01397 
01398     AcGiSubEntityTraits*    mpSubEntityTraits;
01399     AcGiContext*            mpContext;
01400     AcGiRegenType           mRegenType;
01401 
01402     HDWGImporter*           m_pDWGImporter;
01403     AcDbEntity*             m_pAcDbEntity;
01404 
01405 };
01406 
01407 class HAcGiViewportGeometry : public AcGiViewportGeometry
01408 {
01409 public:
01410      ACRX_DECLARE_MEMBERS(HAcGiViewportGeometry);
01411      HAcGiViewportGeometry(HAcGiViewportDraw* pViewportDraw);
01412      ~HAcGiViewportGeometry();
01413     virtual Adesk::Boolean  polylineEye(const Adesk::UInt32 nbPoints,
01414                                 const AcGePoint3d* pPoints) const ;
01415     virtual Adesk::Boolean  polygonEye(const Adesk::UInt32 nbPoints,
01416                                 const AcGePoint3d* pPoints) const ;
01417 
01418     virtual Adesk::Boolean  polylineDc(const Adesk::UInt32 nbPoints,
01419                                 const AcGePoint3d* pPoints) const;
01420     virtual Adesk::Boolean  polygonDc(const Adesk::UInt32 nbPoints,
01421                                 const AcGePoint3d* pPoints) const ;
01422 
01423 
01424     virtual Adesk::Boolean  rasterImageDc(
01425                 const AcGePoint3d& origin,
01426                 const AcGeVector3d& u,
01427                 const AcGeVector3d& v,
01428                 const AcGeMatrix2d& pixelToDc,
01429                 AcDbObjectId entityId,
01430                 AcGiImageOrg imageOrg,
01431                 Adesk::UInt32 imageWidth,
01432                 Adesk::UInt32 imageHeight,
01433                 Adesk::Int16 imageColorDepth,
01434                 Adesk::Boolean transparency,
01435                 ImageSource source,
01436                 const AcGeVector3d& unrotatedU,
01437                 const AcGiImageOrg origionalImageOrg,
01438                 const AcGeMatrix2d& unrotatedPixelToDc,
01439                 const Adesk::UInt32 unrotatedImageWidth,
01440                 const Adesk::UInt32 unrotatedImageHeight
01441                 ) const;
01442 
01443     virtual Adesk::Boolean  ownerDrawDc(
01444                 long                       vpnumber, 
01445                 long                       left, 
01446                 long                       top, 
01447                 long                       right, 
01448                 long                       bottom, 
01449                 const OwnerDraw*           pOwnerDraw
01450                 ) const;
01451 
01452     virtual Adesk::Boolean  ownerDraw3d(
01453                 AcGePoint3d&               minBounds,
01454                 AcGePoint3d&               maxBounds,
01455                 OwnerDraw3d*               pOwnerDraw
01456                 ) const  ;
01457 
01458 
01459     // Coordinate transformations.
01460     //
01461     virtual void getModelToWorldTransform(AcGeMatrix3d&) const ;
01462     virtual void getWorldToModelTransform(AcGeMatrix3d&) const ;
01463 
01464     virtual Adesk::Boolean pushModelTransform(const AcGeVector3d & vNormal) ;// Uses arbitrary Axis algorythm
01465     virtual Adesk::Boolean pushModelTransform(const AcGeMatrix3d & xMat) ;
01466     virtual Adesk::Boolean popModelTransform() ;
01467 
01468     virtual AcGeMatrix3d pushPositionTransform (AcGiPositionTransformBehavior behavior, const AcGePoint3d& offset); 
01469     virtual AcGeMatrix3d pushPositionTransform (AcGiPositionTransformBehavior behavior, const AcGePoint2d& offset); 
01470     virtual AcGeMatrix3d pushScaleTransform (AcGiScaleTransformBehavior behavior, const AcGePoint3d& extents);
01471     virtual AcGeMatrix3d pushScaleTransform (AcGiScaleTransformBehavior behavior, const AcGePoint2d& extents);
01472     virtual AcGeMatrix3d pushOrientationTransform (AcGiOrientationTransformBehavior behavior);
01473     
01474 
01475     // For drawing various primitives.
01476     //
01477     virtual Adesk::Boolean  circle(const AcGePoint3d& center,
01478                                    const double radius,
01479                                    const AcGeVector3d& normal) const ;
01480 
01481     virtual Adesk::Boolean  circle(const AcGePoint3d&, const AcGePoint3d&,
01482                                    const AcGePoint3d&) const ;
01483 
01484     virtual Adesk::Boolean  circularArc(const AcGePoint3d& center,
01485                                    const double radius,
01486                                    const AcGeVector3d& normal,
01487                                    const AcGeVector3d& startVector,
01488                                    const double sweepAngle,
01489                                    const AcGiArcType arcType = kAcGiArcSimple) const ;
01490 
01491     virtual Adesk::Boolean  circularArc(const AcGePoint3d& start,
01492                                    const AcGePoint3d& point,
01493                                    const AcGePoint3d& end,
01494                                    const AcGiArcType arcType = kAcGiArcSimple) const ;
01495       
01496     virtual Adesk::Boolean  polyline(const Adesk::UInt32 nbPoints,
01497                                    const AcGePoint3d* pVertexList,
01498                                    const AcGeVector3d* pNormal = NULL,
01499                                    Adesk::LongPtr lBaseSubEntMarker = -1) const ;
01500       
01501     virtual Adesk::Boolean  polyline(const AcGiPolyline& polylineObj) const {return Adesk::kTrue;}
01502 
01503     virtual Adesk::Boolean  polyPolyline (Adesk::UInt32 nbPolylines,
01504                                           const AcGiPolyline* pPolylines) const {return Adesk::kTrue;}
01505     virtual Adesk::Boolean  polyPolygon(const Adesk::UInt32 numPolygonIndices,
01506                                     const Adesk::UInt32* numPolygonPositions,
01507                                     const AcGePoint3d* polygonPositions,
01508                                     const Adesk::UInt32* numPolygonPoints,
01509                                     const AcGePoint3d* polygonPoints,
01510                                     const AcCmEntityColor* outlineColors = NULL,
01511                                     const AcGiLineType* outlineTypes = NULL,
01512                                     const AcCmEntityColor* fillColors = NULL,
01513                                     const AcCmTransparency* fillOpacities = NULL) const {return Adesk::kTrue;}
01514     virtual Adesk::Boolean  image(const AcGiImageBGRA32& imageSource,
01515                           const AcGePoint3d& position,
01516                           const AcGeVector3d& u, //orientation and magnitude of width
01517                           const AcGeVector3d& v, //orientation and magnitude of height
01518                           TransparencyMode transparencyMode = kTransparency8Bit
01519                           ) const {return Adesk::kTrue;}
01520     virtual Adesk::Boolean  rowOfDots(int count,
01521                                   const AcGePoint3d&     start,
01522                                   const AcGeVector3d&     step
01523                                  ) const {return Adesk::kTrue;}
01524     virtual Adesk::Boolean  ellipticalArc(const AcGePoint3d&         center,
01525                                       const AcGeVector3d&        normal,
01526                                       double                     majorAxisLength,
01527                                       double                     minorAxisLength,
01528                                       double                     startDegreeInRads,
01529                                       double                     endDegreeInRads,
01530                                       double                     tiltDegreeInRads,
01531                                       AcGiArcType                arcType = kAcGiArcSimple
01532                                       ) const {return Adesk::kTrue;}
01533       
01534     virtual Adesk::Boolean  polygon(const Adesk::UInt32 nbPoints,
01535                                    const AcGePoint3d* pVertexList) const ;
01536 
01537     virtual Adesk::Boolean  mesh(const Adesk::UInt32 rows,
01538                                  const Adesk::UInt32 columns,
01539                                  const AcGePoint3d* pVertexList,
01540                                  const AcGiEdgeData* pEdgeData = NULL,
01541                                  const AcGiFaceData* pFaceData = NULL,
01542                                  const AcGiVertexData* pVertexData = NULL,
01543                                  const bool bAutoGenerateNormals = true
01544                                  ) const ;
01545 
01546     virtual Adesk::Boolean  shell(const Adesk::UInt32 nbVertex,
01547                                  const AcGePoint3d* pVertexList,
01548                                  const Adesk::UInt32 faceListSize,
01549                                  const Adesk::Int32* pFaceList,
01550                                  const AcGiEdgeData* pEdgeData = NULL,
01551                                  const AcGiFaceData* pFaceData = NULL,
01552                                  const AcGiVertexData* pVertexData = NULL,
01553                                  const struct resbuf* pResBuf = NULL,
01554                                  const bool bAutoGenerateNormals = true
01555                                  ) const ;
01556       
01557     virtual Adesk::Boolean  text(const AcGePoint3d& position,
01558                                  const AcGeVector3d& normal,
01559                                  const AcGeVector3d& direction,
01560                                  const double height,
01561                                  const double width,
01562                                  const double oblique,
01563                                  const ACHAR* pMsg) const ;
01564 
01565     virtual Adesk::Boolean  text(const AcGePoint3d& position,
01566                                  const AcGeVector3d& normal,
01567                                  const AcGeVector3d& direction,
01568                                  const ACHAR* pMsg,
01569                                  const Adesk::Int32 length,
01570                                  const Adesk::Boolean raw,
01571                                  const AcGiTextStyle &pTextStyle
01572                                  ) const ;
01573 
01574     virtual Adesk::Boolean  xline(const AcGePoint3d&,
01575                                   const AcGePoint3d&) const ;
01576 
01577     virtual Adesk::Boolean  ray(const AcGePoint3d&,
01578                                 const AcGePoint3d&) const ;
01579 
01580     virtual Adesk::Boolean  pline(const AcDbPolyline& lwBuf,
01581                                   Adesk::UInt32 fromIndex = 0,
01582                                   Adesk::UInt32 numSegs = 0
01583                                   ) const ;
01584 
01585     virtual Adesk::Boolean  draw(AcGiDrawable*) const ;
01586 
01587     virtual Adesk::Boolean          pushClipBoundary(AcGiClipBoundary * pBoundary);
01588     virtual void                    popClipBoundary() ;
01589 
01590 private:
01591     // Back pointer stored to the ViewPortDraw object.  This class
01592     // uses it to store the ShellData when the shell member
01593     // function is called. ---- SK 18 mar 09
01594     HAcGiViewportDraw* m_pHAcGiViewportDraw;
01595     unsigned int m_uiOpenSegmentCount;
01596 
01597 };
01598 class HAcGiViewport : public AcGiViewport
01599 {
01600 public:
01601     ACRX_DECLARE_MEMBERS(AcGiViewport);
01602     HAcGiViewport(HInputHandlerOptions const * options = 0);
01603     ~HAcGiViewport();
01604 
01605     virtual void getModelToEyeTransform(AcGeMatrix3d& mx) const;
01606     virtual void getEyeToModelTransform(AcGeMatrix3d& mx) const;
01607     virtual void getWorldToEyeTransform(AcGeMatrix3d& mx) const;
01608     virtual void getEyeToWorldTransform(AcGeMatrix3d& mx) const;
01609 
01610     virtual Adesk::Boolean isPerspective() const;
01611     virtual Adesk::Boolean doPerspective(AcGePoint3d&) const;
01612     virtual Adesk::Boolean doInversePerspective(AcGePoint3d&) const;
01613 
01614      virtual void getNumPixelsInUnitSquare(const AcGePoint3d& givenWorldpt,
01615                                   AcGePoint2d& pixelArea,
01616                                   bool includePerspective = true) const;
01617 
01618     virtual void getCameraLocation(AcGePoint3d& location) const;
01619     virtual void getCameraTarget(AcGePoint3d& target) const;
01620     virtual void getCameraUpVector(AcGeVector3d& upVector) const;
01621 
01622      virtual Adesk::ULongPtr viewportId() const;
01623     virtual Adesk::Int16  acadWindowId() const;
01624     virtual void getViewportDcCorners(AcGePoint2d& lower_left,
01625                                       AcGePoint2d& upper_right) const;
01626 
01627     virtual Adesk::Boolean getFrontAndBackClipValues(Adesk::Boolean& clip_front,
01628                                          Adesk::Boolean& clip_back,
01629                                          double& front,
01630                                          double& back) const;
01631     virtual double linetypeScaleMultiplier() const;
01632     virtual double linetypeGenerationCriteria() const;
01633 
01634     virtual AcGeVector3d viewDir() const;
01635 
01636 private:
01637     HInputHandlerOptions const * inputOptions;
01638     AcGePoint3d cameraTarget;
01639     AcGePoint3d cameraLocation;
01640     AcGeVector3d cameraUpVector;
01641 };
01642 
01643 class HDrawOrderHandler
01644 {
01645 public:
01646     HDrawOrderHandler(AcDbBlockTableRecord * pRecord)
01647     {
01648         m_pRecord = pRecord;
01649         m_pObj = 0;
01650     };
01651 
01652     int Open();
01653     bool GetNextEntity(AcDbEntity *& pOutEnt);
01654     int CheckDrawOrderAndSetVisibility(AcDbEntity * pEnt, HC_KEY block_key, HDWG_3dgsImporter * importer);
01655     int CheckDrawOrderAndSetVisibility(AcDbEntity * pEnt, TK_Open_Segment * include_seg_handler, HDWG_BStreamImporter * importer);
01656     void Close();
01657 
01658 protected:
01659     AcDbBlockTableRecord * m_pRecord;
01660     AcDbSortentsTable * m_pObj;
01661     AcDbObjectIdArray objArray;
01662     int m_iIndex;
01663     AcDbBlockTableRecordIterator * m_pRecordIter;
01664 
01665 };
01666 
01667 wchar_t * h_dwg_wcsdup(wchar_t const * const wcs);
01668 
01669 // Inline functions for HDWG_BStreamImporter calling opcodehandlers
01670 inline int HDWG_BStreamImporter::STREAM_Open_Segment(TK_Open_Segment* open_seg_handler, const char * seg_name) const
01671 {
01672     // Caller have to delete open_seg_handler, in this version.
01673     open_seg_handler->SetSegment(seg_name);
01674     TK_Status hdwg_status = WriteObject(open_seg_handler,m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01675     H_ASSERT(hdwg_status == TK_Normal);
01676     return 1;
01677 }
01678 
01679 inline int HDWG_BStreamImporter::STREAM_Open_Segment(const char * seg_name) const
01680 {
01681     // Caller don't have to delete open_seg_handler, in this version.
01682     TK_Open_Segment* open_seg_handler = new TK_Open_Segment;
01683     open_seg_handler->SetSegment(seg_name);
01684     TK_Status hdwg_status = WriteObject(open_seg_handler,m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01685     H_ASSERT(hdwg_status == TK_Normal);
01686     delete open_seg_handler;
01687 
01688     return 1;
01689 }
01690 
01691 inline int HDWG_BStreamImporter:: STREAM_Close_Segment() const
01692 {
01693     TK_Close_Segment *close_seg_handler = new TK_Close_Segment;
01694     TK_Status hdwg_status = WriteObject(close_seg_handler, m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01695     H_ASSERT(hdwg_status == TK_Normal);
01696     delete close_seg_handler;
01697 
01698     return 1;
01699 }
01700 
01701 inline int HDWG_BStreamImporter:: STREAM_Set_Visibility(TKO_Geometry_Bits Geom_Bit, bool ifOn) const
01702 {
01703     //HC_Set_Visibility("off");
01704     TK_Visibility   *vis_handler = new TK_Visibility();
01705     vis_handler->SetGeometry(Geom_Bit);
01706     if(ifOn)
01707         vis_handler->SetValue(1);
01708     else
01709         vis_handler->SetValue(0);
01710     TK_Status hdwg_status = WriteObject(vis_handler, m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01711     H_ASSERT(hdwg_status == TK_Normal);
01712     delete vis_handler;
01713 
01714     return 1;
01715 }
01716 
01717 inline int HDWG_BStreamImporter:: STREAM_Set_Heuristics(TKO_Heuristic_Bits Heuristic_Bit) const
01718 {
01719     //HC_Set_Heuristics("xxxx");
01720     TK_Heuristics* heuristic_handler = new TK_Heuristics;
01721     heuristic_handler->SetMask( Heuristic_Bit);
01722     heuristic_handler->SetValue( Heuristic_Bit);
01723     TK_Status hdwg_status = WriteObject(heuristic_handler, m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01724     H_ASSERT(hdwg_status == TK_Normal);
01725     delete heuristic_handler;
01726 
01727     return 1;
01728 }
01729 inline int HDWG_BStreamImporter:: STREAM_Write_Object(BBaseOpcodeHandler * handler) const
01730 {
01731     TK_Status  hdwg_status = WriteObject(handler, m_pBStreamtk, m_pHSFFile, m_pBStreamBuffer, m_nBStreamBuffSize);
01732     H_ASSERT(hdwg_status == TK_Normal);
01733     delete handler;
01734 
01735     return 1;
01736 }
01737 
01738 #ifdef H_PACK_8
01739 #pragma pack(pop)
01740 #endif
01741 
01742 #endif