00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 // $Id: 418c31fa0dc81cb2c551bbd83b115e3f4c114174 $ 00013 // 00014 00015 #ifndef _HSKPHELPER_H 00016 #define _HSKPHELPER_H 00017 00018 #ifndef CLASS_HSKPImporter_DEF 00019 #define CLASS_HSKPImporter_DEF 00020 #include <atlbase.h> 00021 #include <atlcom.h> 00022 #include <comdef.h> 00023 using namespace ATL; 00024 #include "SketchUp_i.h" 00025 #include "SketchUpAddin.h" 00026 #endif 00027 00028 #ifdef H_PACK_8 00029 #pragma pack(push) 00030 #pragma pack(8) 00031 #endif 00032 00033 // HOOPS/MVO includes 00034 #include "HDB.h" 00035 #include "HIOManager.h" 00036 00037 #include <iostream> 00038 #include <map> 00039 using namespace std; 00040 00041 #include "InheritanceManager.h" 00042 #include "HResult.h" 00043 00044 // Mesh can be created with optional UV front/back coordinates, 00045 // and optional normal vectors. UV coordinates are 00046 // currently Point3d's with X=U, Y=V, Z=Q. Q will always be 1 00047 // for affine texture transforms. 00048 #define PolygonMeshPoints 0 00049 #define PolygonMeshUVQFront 1 00050 #define PolygonMeshUVQBack 2 00051 #define PolygonMeshNormals 4 00052 00053 template<typename K, typename V> 00054 class SKPMap 00055 { 00056 public: 00057 typedef typename std::map<K,V>::iterator Iter; 00058 00059 SKPMap() {} 00060 00061 void Add(K key, V value) 00062 { 00063 _data[key] = value; 00064 } 00065 00066 void Add(K key, V value, Iter it) 00067 { 00068 _data.insert(it, std::pair<K, V>(key, value)); 00069 } 00070 00071 V Get(K key) 00072 { 00073 return _data[key]; 00074 } 00075 00076 bool Contains(K key) 00077 { 00078 return _data.find(key) != _data.end(); 00079 } 00080 00081 bool Contains(K key, Iter &it) 00082 { 00083 it = _data.find(key); 00084 return it != _data.end(); 00085 } 00086 00087 private: 00088 std::map<K,V> _data; 00089 }; 00090 00091 typedef SKPMap<long, HC_KEY> LongKeyMap; 00092 typedef SKPMap<std::string, HC_KEY> NameKeyMap; 00093 00094 typedef unsigned __int16 Checksum; 00095 00096 class HSKPImporter 00097 { 00098 typedef unsigned int TextureParamId; 00099 00100 public: 00101 HSKPImporter(CComPtr<ISkpTextureWriter2> textureWriter); 00102 ~HSKPImporter(); 00103 00104 void setTotalEntities(CComPtr<ISkpDocument> pDoc); 00105 void setInputHandler(HInputHandler* val){m_pInputhandler = val;}; 00106 00107 HInputHandler* getInputHandler() 00108 { 00109 return m_pInputhandler; 00110 }; 00111 void set_IgnoreEntities(bool val){ m_bIgnoreEntities = val;}; 00112 00113 CComPtr<ISkpDocument> getSKPDatabase(const char *, CComPtr<ISkpApplication> pApp); 00114 void importSKPPages(CComPtr<ISkpDocument> pDoc,HInputHandlerOptions * options); 00115 void importSKPText(CComPtr<ISkpEntityProvider> ); 00116 void setDefaultOptions(CComPtr<ISkpDocument> pDoc); 00117 void conditionStringForSegName(char* zString); 00118 void setTextureDirectory(); 00119 void transformPointsFromRotationTranslate(double *angle,HPoint* axis, HPoint* points,HPoint* origin); 00120 double round(double x); 00121 void fitToScene(HInputHandlerOptions * options); 00122 BOOL deleteDirectory(const TCHAR* sPath); 00123 BOOL isDots(const TCHAR* str); 00124 void set_importMetadata(bool mdata) 00125 { 00126 m_bImportMetadata = mdata; 00127 } 00128 00129 00130 00131 void ImportGeometry(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00132 00133 private: 00134 void ImportComponents(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00135 void ImportGroups(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00136 void ImportImages(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00137 void ImportFaces(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00138 void ImportEdges(CComPtr<ISkpEntityProvider> entityProvider, int depth); 00139 00140 void ImportRpReportsAttributes(CComPtr<ISkpAttributeProvider> attributeProvider); 00141 void ImportMaterial(CComPtr<ISkpMaterial> material, long textureHandle, const char *localTextureName); 00142 void ImportTransform(CComPtr<ISkpTransform> transform); 00143 void ImportFace(CComPtr<ISkpFace> face, int depth, NameKeyMap & foundMaterials); 00144 00145 // Returns ISkpEntity id. item must implement ISkpEntity 00146 static long GetEntityId(IUnknown *item); 00147 00148 void ReadOptionsProvider(const char* title, CComPtr<ISkpNamedValues> pNVs); 00149 00150 bool loadImage(long handle, BSTR in_name, char * out_name, TextureParamId textureParamId); 00151 bool loadTexture(CComPtr<ISkpMaterial> material, long texHandle, char * out_texName, TextureParamId textureParamId); 00152 bool getMaterialTextureColor(CComPtr<ISkpMaterial> material, long textureHandle, char *out_color, TextureParamId textureParamId); 00153 bool getMaterialRGBColor(CComPtr<ISkpMaterial> material, char *out_color); 00154 bool getMaterialTransmissionColor(CComPtr<ISkpMaterial> material, char *out_color, bool *out_isTranslucent); 00155 bool getMaterialColor(CComPtr<ISkpMaterial> material, long textureHandle, char *out_color, bool *out_isTranslucent); 00156 bool getOneFaceColor(CComPtr<ISkpFace> face, CComPtr<ISkpMaterial> material, BOOL front, char *out_color, bool *out_isTranslucent, TextureParamId textureParamId); 00157 bool getFaceColor(CComPtr<ISkpFace> face, char *out_color, TextureParamId textureParamId); 00158 00159 private: 00160 HInputHandler * m_pReader; 00161 HInputHandler * m_pInputhandler; 00162 00163 CComPtr<ISkpTextureWriter2> m_pTextureWriter; 00164 00165 char m_cTextureDirectory[MVO_BUFFER_SIZE]; 00166 bool m_bIsColorByLayer; 00167 bool m_bIgnoreEntities; 00168 bool m_bImportMetadata; 00169 bool m_bSkpFitworld; 00170 long m_totalEntities; 00171 00172 TextureParamId m_nextTextureParamId; 00173 00174 typedef std::pair<std::string, Checksum> FileChecksum; 00175 std::map<FileChecksum, std::string> m_canonicalTextures; 00176 00177 CInheritanceManager m_inheritanceManager; 00178 LongKeyMap m_importedCompDefs; 00179 }; 00180 00181 00182 #ifdef H_PACK_8 00183 #pragma pack(pop) 00184 #endif 00185 00186 #endif 00187 //#endif 00188 00189 00190