00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <stdio.h>
00047 #include <UT/UT_DSOVersion.h>
00048 #include <CMD/CMD_Manager.h>
00049 #include <CMD/CMD_Args.h>
00050
00051 #include <UI/UI_Value.h>
00052 #include <SI/AP_Interface.h>
00053
00054 #include <time.h>
00055
00056
00057 #define MYDIALOG_CB(method) ((UI_EventMethod)&MyDialog::method)
00058
00059
00060
00061
00062 namespace HDK_Sample {
00063
00064 class MyDialog : public AP_Interface
00065 {
00066 public:
00067 MyDialog();
00068
00069
00070 bool open();
00071
00072
00073 void close();
00074
00075 private:
00076
00077 bool parseDialog();
00078
00079
00080
00081 void handleImport(UI_Event *event);
00082 void handleOpenOrClose(UI_Event *event);
00083
00084
00085 private:
00086 UI_Value myOpenValue;
00087 UI_Value myStatusValue;
00088 bool myParsedDialog;
00089 bool myIsOpen;
00090 };
00091
00092 }
00093
00094 using namespace HDK_Sample;
00095
00096 MyDialog::MyDialog()
00097 : myParsedDialog(false)
00098 , myIsOpen(false)
00099 {
00100 }
00101
00102 bool
00103 MyDialog::parseDialog()
00104 {
00105
00106
00107
00108 setValueSymbol("dlg.val", &myOpenValue);
00109 setValueSymbol("status.val", &myStatusValue);
00110
00111
00112
00113 if (!parseUI("cmd_ui/cmd_ui.ui"))
00114 return false;
00115
00116
00117 myOpenValue.addInterest(this, MYDIALOG_CB(handleOpenOrClose));
00118
00119 getValueSymbol("import.val")->addInterest(this, MYDIALOG_CB(handleImport));
00120
00121 return true;
00122 }
00123
00124 bool
00125 MyDialog::open()
00126 {
00127
00128 if (!myParsedDialog)
00129 {
00130 if (!parseDialog())
00131 return false;
00132 myParsedDialog = true;
00133 }
00134
00135 myStatusValue = "";
00136
00137 myOpenValue = true;
00138 myOpenValue.changed(this);
00139 return true;
00140 }
00141
00142 void
00143 MyDialog::close()
00144 {
00145 myOpenValue = false;
00146 myOpenValue.changed(this);
00147 }
00148
00149 void
00150 MyDialog::handleOpenOrClose(UI_Event *event)
00151 {
00152
00153 if (myIsOpen == (bool)myOpenValue)
00154 return;
00155 myIsOpen = (bool)myOpenValue;
00156
00157 if (myIsOpen)
00158 {
00159 printf("dialog was opened\n");
00160 }
00161 else
00162 {
00163 printf("dialog was closed\n");
00164 }
00165 }
00166
00167 void
00168 MyDialog::handleImport(UI_Event *event)
00169 {
00170
00171
00172 printf("Filename %s\n", (const char *)*getValueSymbol("filename.val"));
00173 printf("Menu index %d\n", (int)*getValueSymbol("mymenu.val"));
00174 printf("Cameras %d\n", (bool)*getValueSymbol("cameras.val"));
00175 printf("Lights %d\n", (bool)*getValueSymbol("lights.val"));
00176 printf("Geometry %d\n", (bool)*getValueSymbol("geometry.val"));
00177 printf("Animation %d\n", (bool)*getValueSymbol("animation.val"));
00178 printf("Attributes %d\n", (int)*getValueSymbol("attrib.val"));
00179
00180
00181 myStatusValue = "Import Successful!";
00182 myStatusValue.changed(this);
00183 }
00184
00185
00186
00187
00188
00189 static void
00190 cmd_ui( CMD_Args &args )
00191 {
00192 static MyDialog dlg;
00193
00194 if (!dlg.open())
00195 args.err() << "Could not parse cmd_ui.ui file" << endl;
00196 else
00197 args.out() << "Successfully launched dialog" << endl;
00198 }
00199
00200
00201
00202 void
00203 CMDextendLibrary( CMD_Manager *cman )
00204 {
00205
00206 cman->installCommand("cmd_ui", "", cmd_ui);
00207 }
00208