Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HSKPHelper.h
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$
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 #include <map>      // switch to unordered_map when no longer using vs2008
00054 
00055 template<typename K, typename V>
00056 class SKPMap
00057 {
00058 public:
00059     typedef typename std::map<K,V>::iterator    Iter;
00060 
00061     SKPMap() {}
00062 
00063     void Add(K key, V value)
00064     {
00065         _data[key] = value;
00066     }
00067 
00068     void Add(K key, V value, Iter it)
00069     {
00070         _data.insert(it, std::pair<K, V>(key, value));
00071     }
00072 
00073     V Get(K key)
00074     {
00075         return _data[key];
00076     }
00077 
00078     bool Contains(K key)
00079     {
00080         return _data.find(key) != _data.end();
00081     }
00082 
00083     bool Contains(K key, Iter &it)
00084     {
00085         it = _data.find(key);
00086         return it != _data.end();
00087     }
00088 
00089 private:
00090     std::map<K,V>                   _data;
00091 };
00092 
00093 typedef SKPMap<long, HC_KEY>            LongKeyMap;
00094 typedef SKPMap<std::string, HC_KEY>     NameKeyMap;
00095 
00096 class HSKPImporter
00097 {
00098 public:
00099     HSKPImporter(CComPtr<ISkpTextureWriter2> textureWriter);
00100     ~HSKPImporter();
00101 
00102     void setTotalEntities(CComPtr<ISkpDocument> pDoc);
00103     void setInputHandler(HInputHandler* val){m_pInputhandler = val;};
00104     
00105     HInputHandler* getInputHandler()
00106     {
00107         return m_pInputhandler;
00108     };
00109     void set_IgnoreEntities(bool val){ m_bIgnoreEntities = val;};
00110 
00111     CComPtr<ISkpDocument> getSKPDatabase(const char *, CComPtr<ISkpApplication> pApp);
00112     void importSKPPages(CComPtr<ISkpDocument> pDoc,HInputHandlerOptions * options);
00113     void importSKPText(CComPtr<ISkpEntityProvider> );
00114     void setDefaultOptions(CComPtr<ISkpDocument> pDoc);
00115     void conditionStringForSegName(char* zString);
00116     void setTextureDirectory();
00117     void transformPointsFromRotationTranslate(double *angle,HPoint* axis, HPoint* points,HPoint* origin);
00118     double round(double x);
00119     void fitToScene(HInputHandlerOptions * options);
00120     BOOL deleteDirectory(const TCHAR* sPath);
00121     BOOL isDots(const TCHAR* str);
00122     void set_importMetadata(bool mdata)
00123     {
00124         m_bImportMetadata = mdata;
00125     }
00126 
00127 
00128 
00129     void ImportGeometry(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00130 
00131 private:
00132     void ImportComponents(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00133     void ImportGroups(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00134     void ImportImages(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00135     void ImportFaces(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00136     void ImportEdges(CComPtr<ISkpEntityProvider> entityProvider, int depth);
00137 
00138     void ImportRpReportsAttributes(CComPtr<ISkpAttributeProvider> attributeProvider);
00139     void ImportMaterial(CComPtr<ISkpMaterial> material, long textureHandle, const char *localTextureName);
00140     void ImportTransform(CComPtr<ISkpTransform> transform);
00141     void ImportFace(CComPtr<ISkpFace> face, int depth, NameKeyMap & foundMaterials);
00142 
00143     // Returns ISkpEntity id.  item must implement ISkpEntity
00144     static long GetEntityId(IUnknown *item);
00145 
00146     void ReadOptionsProvider(CComPtr<ISkpNamedValues> pNVs);
00147 
00148     bool loadImage(long handle, BSTR in_name, char * out_name, CComPtr<ISkpFace> face = 0);
00149     bool loadTexture(CComPtr<ISkpMaterial> material, long texHandle, char * out_texName, CComPtr<ISkpFace> face);
00150     bool getMaterialTextureColor(CComPtr<ISkpMaterial> material, long textureHandle, char *out_color, CComPtr<ISkpFace> face = 0);
00151     bool getMaterialRGBColor(CComPtr<ISkpMaterial> material, char *out_color);
00152     bool getMaterialTransmissionColor(CComPtr<ISkpMaterial> material, char *out_color, bool *out_isTranslucent);
00153     bool getMaterialColor(CComPtr<ISkpMaterial> material, long textureHandle, char *out_color, bool *out_isTranslucent);
00154     bool getOneFaceColor(CComPtr<ISkpFace> face, CComPtr<ISkpMaterial> material, BOOL front, char *out_color, bool *out_isTranslucent);
00155     bool getFaceColor(CComPtr<ISkpFace> face, char *out_color);
00156 
00157 private:
00158     HInputHandler *         m_pReader;
00159     HInputHandler *         m_pInputhandler;
00160 
00161     CComPtr<ISkpTextureWriter2> m_pTextureWriter;
00162 
00163     char                    m_cTextureDirectory[MVO_BUFFER_SIZE];
00164     bool                    m_bIsColorByLayer;
00165     bool                    m_bIgnoreEntities;
00166     bool                    m_bImportMetadata;
00167     bool                    m_bSkpFitworld;
00168     long                    m_totalEntities;
00169 
00170     std::multimap<long, std::pair<long, string> > m_textures;
00171 
00172     CInheritanceManager     m_inheritanceManager;
00173     LongKeyMap              m_importedCompDefs;
00174 };
00175 
00176 
00177 #ifdef H_PACK_8
00178 #pragma pack(pop)
00179 #endif
00180 
00181 #endif
00182 //#endif
00183 
00184 
00185