]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtAddMesh.cxx
#3037 creaWT Bug New Normal - AddMesh update
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtAddMesh.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbwtAddMesh.h"
5 #include "bbwtPackage.h"
6
7 #include<Wt/WApplication>
8
9
10 namespace bbwt
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,AddMesh)
14 BBTK_BLACK_BOX_IMPLEMENTATION(AddMesh,bbtk::AtomicBlackBox);
15 //===== 
16 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
17 //===== 
18 void AddMesh::Process()
19 {
20
21 // THE MAIN PROCESSING METHOD BODY
22 //   Here we simply set the input 'In' value to the output 'Out'
23 //   And print out the output value
24 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
25 //    void bbSet{Input|Output}NAME(const TYPE&)
26 //    const TYPE& bbGet{Input|Output}NAME() const 
27 //    Where :
28 //    * NAME is the name of the input/output
29 //      (the one provided in the attribute 'name' of the tag 'input')
30 //    * TYPE is the C++ type of the input/output
31 //      (the one provided in the attribute 'type' of the tag 'input')
32
33
34         std::string meshFileName=bbGetInputMesh();
35
36         printf("EED AddMesh::Process meshFileName=%s\n",meshFileName.c_str());
37
38         bool ok=true;
39     FILE *ff = fopen( bbGetInputMesh().c_str(), "r" );
40         char strtmp[255];
41         long int numberPoints;
42     if (ff==NULL)
43     {
44                 ok=false;
45         } else {
46                 fgets(strtmp,255,ff);
47                 fgets(strtmp,255,ff);
48                 fgets(strtmp,255,ff);
49                 fgets(strtmp,255,ff);
50                 fscanf(ff,"%s %ld", strtmp,&numberPoints );
51                 if (numberPoints==0)
52                 {
53                         ok=false;
54                 }
55             fclose(ff);
56         }
57
58         Wt::WContainerWidget* w = (Wt::WContainerWidget*)bbGetInputViewerWt();
59         char strPointer[15];
60         sprintf(strPointer,"%p",this);
61         std::string mMesh               = w->jsRef() + ".mMesh"+strPointer;
62         std::string mRemoveActor= w->jsRef() + ".mRemoveActor"+strPointer;
63         std::string mRenderer   = w->jsRef() + ".mRenderer";
64
65         if (ok==false)
66         {
67                 ok=false;
68                 meshFileName="imagesTMP/bunny.vtk"; 
69         }
70
71
72 /*
73                                 mMesh.transform.translateX(88.9);\
74                                 mMesh.transform.translateY(102.9);\
75                                 mMesh.transform.rotateZ(180);\
76 */
77
78 /*
79                                 " + mCont+" = false;\
80                                 "+mRenderer+".onShowtime = function()\
81                                         {\
82                                                 if(!" + mCont +")\
83                                                 {\
84                                                         " + mMesh+".visible = true;\
85                                                         " + mCont+" = true;\
86                                                 }\
87                                         };\
88 */
89
90     if (ok==true)
91     {
92                   std::string jsCom = "\
93                         try\
94                         {\
95                                 if ("+mRemoveActor+"==true){ " + mRenderer+".add( " + mMesh+");  } \
96                                 " + mMesh+".transform.matrix.identity;\
97                                 " + mMesh+".transform.translateX(88.9);\
98                                 " + mMesh+".transform.translateY(102.9);\
99                                 " + mMesh+".transform.rotateZ(180);\
100                                 " + mMesh+".opacity = 1;\
101                                 " + mMesh+".file = '"+meshFileName+"';\
102                                 " + mMesh+".modified(true);\
103                                 " + mMesh+".color = [0,1,1];\
104                                 " + mRenderer+".render();\
105                         } catch(err) {\
106                         var mMesh = new X.mesh();\
107                                 " + mMesh+" = mMesh;\
108                                 mMesh.file = '"+meshFileName+"';\
109                                 mMesh.color = [1,1,0];\
110                                 mMesh.opacity=0.5;\
111                                 mMesh.transform.matrix.makeOrtho;\
112                                 "+mRemoveActor+" = false;\
113                         "+mRenderer+".add("+mMesh+");\
114                                 "+mRenderer+".render();\
115                     }";
116 //              std::cout<<"DEBUG ADD OBJECT ----  "<<jsCom<<std::endl;
117 //              w->doJavaScript(jsCom);
118                 Wt::WApplication::instance()->doJavaScript(jsCom);
119         } else { 
120                 std::string jsCom = "\
121                         try\
122                         {\
123                                 "+mRenderer+".remove("+mMesh+");\
124                                 "+mRemoveActor+"=true;\
125                         } catch(err) {\
126                         }";
127                 Wt::WApplication::instance()->doJavaScript(jsCom);
128         }// ok
129 }
130
131 //===== 
132 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
133 //===== 
134 void AddMesh::bbUserSetDefaultValues()
135 {
136
137 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
138 //    Here we initialize the input 'In' to 0
139    bbSetInputMesh("<void>");
140    bbSetInputViewerWt(NULL);
141   
142 }
143 //===== 
144 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
145 //===== 
146 void AddMesh::bbUserInitializeProcessing()
147 {
148
149 //  THE INITIALIZATION METHOD BODY :
150 //    Here does nothing 
151 //    but this is where you should allocate the internal/output pointers 
152 //    if any 
153
154   
155 }
156 //===== 
157 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
158 //===== 
159 void AddMesh::bbUserFinalizeProcessing()
160 {
161
162 //  THE FINALIZATION METHOD BODY :
163 //    Here does nothing 
164 //    but this is where you should desallocate the internal/output pointers 
165 //    if any
166   
167 }
168 }
169 // EO namespace bbwt
170
171