]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/brushexport/plugin.cpp
- Weird shiftvalues are now hidden to the user, shiftvalues will
[xonotic/netradiant.git] / contrib / brushexport / plugin.cpp
index 8954473dc3de68ea4b5f283d16c2e2fd8c82c982..1b5e7c19219aaa82d893aad521b8cb922269029d 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "qerplugin.h"\r
 \r
 #include <gtk/gtk.h>\r
+#include <gtk/gtktreeview.h>\r
 \r
 #include "debugging/debugging.h"\r
 #include "string/string.h"\r
@@ -39,109 +40,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "ifilesystem.h"\r
 #include "ifiletypes.h"\r
 \r
-#include "../../radiant/brush.h"\r
+#include "support.h"\r
+\r
+#include "typesystem.h"\r
+\r
+void CreateWindow (void);\r
+void DestroyWindow(void);\r
+bool IsWindowOpen(void);\r
 \r
 namespace BrushExport\r
-{ \r
+{\r
   GtkWindow* g_mainwnd;\r
   \r
-  class CExportFormatWavefront : public BrushVisitor\r
-  {\r
-    TextFileOutputStream& m_file;\r
-\r
-    StringOutputStream vertexbuffer;\r
-    StringOutputStream texcoordbuffer;\r
-    StringOutputStream facebuffer;\r
-    \r
-    size_t vertices;\r
-    size_t exported;\r
-    \r
-  public:\r
-    \r
-    CExportFormatWavefront(TextFileOutputStream& file)\r
-        : m_file(file)\r
-    {\r
-      exported = 0;\r
-      vertices = 0;\r
-    }\r
-    \r
-    virtual ~CExportFormatWavefront(void) {}\r
-    \r
-    void visit(scene::Instance& instance)\r
-    {\r
-      BrushInstance* bptr = InstanceTypeCast<BrushInstance>::cast(instance);\r
-      if(bptr)\r
-      {\r
-        Brush& brush(bptr->getBrush());\r
-        \r
-        m_file << "\ng " << brush.name() << exported << "\n";\r
-        \r
-        brush.forEachFace(*this);\r
-    \r
-        m_file << vertexbuffer.c_str() << "\n";\r
-        m_file << texcoordbuffer.c_str();\r
-        m_file << facebuffer.c_str() << "\n";\r
-        \r
-        vertexbuffer.clear();\r
-        texcoordbuffer.clear();\r
-        facebuffer.clear();\r
-        ++exported;\r
-      }\r
-    }\r
-   \r
-    void visit(Face& face) const\r
-    {\r
-      // cast the stupid const away\r
-      const_cast<CExportFormatWavefront*>(this)->visit(face);\r
-    }\r
-    \r
-    void visit(Face& face)\r
-    {\r
-      size_t v_start = vertices;\r
-      const Winding& w(face.getWinding());\r
-      for(size_t i = 0; i < w.numpoints; ++i)\r
-      {\r
-        vertexbuffer << "v " << w[i].vertex.x() << " " << w[i].vertex.y() << " " << w[i].vertex.z() << "\n";\r
-        texcoordbuffer << "vt " << w[i].texcoord.x() << " " << w[i].texcoord.y() << "\n";\r
-        ++vertices;\r
-      }\r
-      \r
-      facebuffer << "\nf";\r
-      for(size_t i = v_start; i < vertices; ++i)\r
-        facebuffer << " " << i+1 << "/" << i+1;\r
-    }\r
-  };\r
-  \r
-  /**\r
-    Exporterclass which will pass every visit-call\r
-    to a special formatexporter.\r
-  */\r
-  template<class TExporterFormat>\r
-  class CExporter : public SelectionSystem::Visitor\r
-  {\r
-  public:\r
-    CExporter(TextFileOutputStream& file)\r
-      : m_exporter(file)\r
-    {}\r
-    \r
-    virtual ~CExporter(void) {}\r
-    \r
-    void visit(scene::Instance& instance) const\r
-    {\r
-      m_exporter.visit(instance);\r
-    }\r
-    \r
-  private:\r
-    mutable TExporterFormat m_exporter;\r
-  };\r
-  \r
-  template<class T>\r
-  void export_selected(TextFileOutputStream& file)\r
-  {\r
-    CExporter<T> exporter(file);\r
-    GlobalSelectionSystem().foreachSelected(exporter);\r
-  }\r
-\r
   const char* init(void* hApp, void* pMainWidget)\r
   {\r
     g_mainwnd = (GtkWindow*)pMainWidget;\r
@@ -165,31 +75,19 @@ namespace BrushExport
   {\r
     if(string_equal(command, "About"))\r
     {\r
-      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Brushexport plugin v 1.0 by namespace (www.codecreator.net)\n"\r
+      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Brushexport plugin v 2.0 by namespace (www.codecreator.net)\n"\r
                                         "Enjoy!\n\nSend feedback to spam@codecreator.net", "About me...",\r
                                         eMB_OK,\r
                                         eMB_ICONDEFAULT);\r
     }\r
     else if(string_equal(command, "Export selected as Wavefront Object"))\r
     {\r
-      if(const char* path = GlobalRadiant().m_pfnFileDialog(GTK_WIDGET(g_mainwnd), false, "Save as Obj", 0, 0))\r
-      {\r
-        TextFileOutputStream file(path); \r
-        if(file.failed())\r
-        {\r
-          GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Unable to write to file", "Error",\r
-                                        eMB_OK,\r
-                                        eMB_ICONERROR);\r
-        }\r
-        else\r
-        {\r
-          export_selected<CExportFormatWavefront>(file);\r
-        }\r
-      }\r
+      if(IsWindowOpen())\r
+           DestroyWindow();\r
+      CreateWindow();\r
     }\r
   }\r
-  \r
-} // namespace\r
+}\r
 \r
 class BrushExportDependencies :\r
   public GlobalRadiantModuleRef,\r
@@ -210,7 +108,7 @@ class BrushExportModule : public TypeSystemRef
   _QERPluginTable m_plugin;\r
 public:\r
   typedef _QERPluginTable Type;\r
-  STRING_CONSTANT(Name, "brushexport");\r
+  STRING_CONSTANT(Name, "brushexport2");\r
 \r
   BrushExportModule()\r
   {\r