root/InOutExpositor/oClient.pde

Revision 5972babe7c40454704b75ea69ba2e12d80927eaa, 13.0 kB (checked in by Robin Gareus <robin@…>, 3 years ago)

fixed expositor to compile w/processing-1.0.9

  • Property mode set to 100644
Line 
1/////////////////////////////////////////////////////////////////////////////////////
2// See the InOutServer comments for more informations on the Client class
3/////////////////////////////////////////////////////////////////////////////////////
4class Client {
5  //////////////
6  int id ;
7  //////////////// ALIVE
8  boolean connected ;
9  boolean goingToDisconnect ;
10  //////////////// CONNEXION
11  String login ;
12  String ip ;
13  String Vip, Aip ; // Streams
14  ////////////// DATE
15  String lastDate, firstDate ;
16  ////////////// PROJECT
17  String name,author,descr,location ;
18  float sReachability, sActivity, sSociability, sWeight ;
19  /////////////////// IN/OUT Profile
20  Aspiration[] in ;
21  Determinant[] out ;
22  ///////////////////
23  float pw = 80 ;
24  float ph = 60 ;
25  /////////////////// PREVIEWS / PNGs
26  boolean showPreview = false ;
27  boolean showSmallPreview = false ;
28  Pnger thePNGs ; // for .png previews
29  //////////////// PHYSICS / SPRINGS
30  Particle p ;
31  Particle c ;
32  Spring anchorLink ;
33  Vector springLinks ; // between Clients
34  Vector tagSprings ; // between Tags
35  Vector repulsionLinks ;
36  //////////////// TENTACULES
37  Vector tentacules ;
38  //////////////// POSITION / ANGLE
39  float angle ; // between 0 and 2*PI
40  float nx, ny, t, ang, nang, r, nr ;
41  //////////////// THINGS
42  Explorator Exp ;
43  boolean roundImageDone = false ;
44
45  //////////////// For the parcours ellipse view
46  boolean toBeCloned = false ;
47
48  int rollPreviewType = 0 ;
49  float selZone = 12 ;
50
51  Client( int _id, String _login, String _name, String _descr, Aspiration[] inA, Determinant[] outD ) { // Creation of USER
52    id = _id ;
53    login = _login ;
54    name = _name ;
55    descr = _descr ;
56    goingToDisconnect = false ;
57    connected = true ;
58
59    ip="-";
60    Vip="-";
61    Aip="-";
62
63    firstDate = lastDate = getTimeStamp() ;
64
65    in = new Aspiration[3] ;
66    out = new Determinant[3] ;
67    in = inA ;
68    out = outD;
69
70    buildPositionAndParticle() ;
71    buildExplorator(0,0) ;
72
73    thePNGs = new Pnger(id,login) ;
74  }
75  void buildPositionAndParticle() {
76    ////////// Position
77    float _x,_y ;
78    float bor = 200 ;
79    _x = random(bor,width-bor) ;
80    _y = random(upControlZone+bor, height-bor) ;
81    //_x = width/2 ;
82    //_y = centerY ;
83
84    ////////// Particle
85    p = physics.makeParticle( 1.0, _x, _y, 0 );
86    c = physics.makeParticle( 1.0, _x, _y, 0 ); // link with the initial position (on a cicle)
87    c.makeFixed() ;
88    anchorLink = physics.makeSpring( p, c, 0.1, 0.1, 2 );
89    springLinks = new Vector() ;
90    repulsionLinks = new Vector() ;
91    angle = random(-PI,PI) ;
92
93    ////////// Tentacules (in et out dispos)
94    tentacules=new Vector() ;
95    for(int u=0;u<6;u++) {
96      TentacSimple tend = new TentacSimple(p,u) ;
97      tentacules.addElement(tend) ;
98    }
99  }
100  ////////////////////////////////
101  void buildExplorator( int idepth, int odepth ) {
102    Exp = new Explorator( this, idepth, odepth ) ;
103  }
104  void traceExplorator() {
105    Exp.trace(false) ; // IN
106    Exp.trace(true) ; // OUT
107  }
108  ////////////////////////////////////////////////////////////
109  void setIP( String newIp ) {
110    if(newIp.charAt(0)=='/') {
111      String[] ipTab = split(newIp,"/") ;
112      ip = ipTab[1] ;
113    }
114    else ip = newIp ;
115
116    connected = !ip.equals("Offline") ;
117  }
118  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120  void traceTentacules() {
121    boolean show=false ;
122    for(int i=0;i<6;i++) {
123      if(i<=2) show=in[i].on ;
124      else show=out[i-3].on ;
125      if(show) ((TentacSimple)tentacules.elementAt(i)).trace() ;
126    }
127  }
128  void traceOutLinks() {
129    if(showType[0]) traceOutLinks(0) ;
130    if(showType[1]) traceOutLinks(1) ;
131    if(showType[2]) traceOutLinks(2) ;
132  }
133  void traceOutLinks( int type ) {
134    Vector outCopins = getOutLinkedClients(this,type) ;
135    Client copin ;
136    for(int i=0;i<outCopins.size();i++) {
137      copin = (Client)outCopins.elementAt(i) ;
138      if(showLinkArcs)        drawArcLink(copin,this,false,type) ;
139      if(showLinkCurves)      drawArcLink(copin,this, true,type) ;
140      if(showLinkDirect)      drawOrientedDottedLine(this, copin,type) ;
141      if(showLinkSimple)      drawOrientedSimpleLine(this,copin,type) ;
142      if(showLinkHalfCircles) drawHalfCircle( this, copin, hwcYPos, type ) ;
143    }
144  }
145  void traceClientCloneAt(float x, float y, float op) {
146    noStroke() ;
147    fill(255,op) ;
148    ellipse( x, y, 7, 7 );
149    if(!onlyRolloverText || (highlighted==this || selected==this)) {
150      String clientInfos = getInfosString() ;
151      textFont(font,10);
152      text(this.name,x+10,y+17) ;
153    }
154  }
155  void traceClientWeight() {
156    if(connected) {
157      stroke(190,140,140) ;
158      fill(190,140,140,100) ;
159    }
160    else {
161      stroke(190,140,140) ;
162      fill(190,140,140,30) ;
163    }
164    float ss = 30+sWeight*90 ;
165    ellipse( x(), y(), ss, ss );
166  }
167  void traceClientPoint() {
168    noStroke() ;
169    if(connected) fill(255) ;
170    else fill(200,150) ;
171    float ss = 8 ;
172    if(!connected) ss = 5 ;
173    ellipse( x(), y(), ss, ss );
174  }
175  void traceClient() {
176    if(t!=-1) goingToNewPos() ;
177
178    if(showStatsBackg) traceClientWeight() ;
179
180    if(showTentacules) traceTentacules() ;
181
182    if(springsToAnchor) traceLinkToAnchor() ;
183
184    if(isInside(mouseX,mouseY) && !mousePressed) highlighted = this ;
185
186    if(highlighted==this || selected==this) {
187      noFill() ;
188      stroke(240) ;
189      ellipse( x(), y(), 14, 14 );
190    }
191    if(showClientBox) {
192      int col = 220 ;
193      if(!connected) col = 100 ;
194      stroke(col) ;
195      fill(col,150) ;
196      traceBox(x(),y()) ;
197    }
198
199    traceClientPoint() ;
200
201    if(!onlyRolloverText || (highlighted==this || selected==this)) {
202      String clientInfos = getInfosString() ;
203      textFont(font,10);
204      text(clientInfos,x()+10,y()+17) ;
205    }
206  }
207  ////////////////////////////////////////////////////////////
208  void setTo(float _x, float _y) {
209    c.moveTo(_x,_y,0) ;
210    p.moveTo(_x,_y,0) ;
211    t=-1 ;
212  }
213  void setPositionTo(float _x, float _y) {
214    c.moveTo(_x,_y,0) ;
215    p.moveTo(_x,_y,0) ;
216  }
217  void moveTo(float _x, float _y) {
218    t=0 ;
219    nx=_x ;
220    ny=_y ;
221    nang=atan2((ny-centerY),(nx-width/2)) ;
222    nr=dist(width/2,centerY,nx,ny) ;
223  }
224  void setFixedAnchorPosition(float _x, float _y) {
225    //moveTo(_x,_y) ;
226    //float ecar = 100 ;
227    //p.moveTo(_x,_y,0) ;
228    //p.moveTo(_x+random(-ecar,ecar),_y+random(-ecar,ecar),0) ;
229  }
230  ////////////////////////////////////////////////////////////
231  void goingToNewPos() {
232    if (radialClientsMovement) goingToNewPosRadial() ;
233    else goingToNewPosLinear() ;
234  }
235  void goingToNewPosLinear() {
236    t++ ;
237    float cx = lerp(nx,x(),clientsSpeedFactor+0.05/(t+1)) ;
238    float cy = lerp(ny,y(),clientsSpeedFactor+0.05/(t+1)) ;
239    setPositionTo(cx,cy) ;
240    if(abs(nx-x())<1 && abs(ny-y())<1) {
241      t=-1 ;
242      setPositionTo(nx,ny) ;
243    }
244  }
245  void goingToNewPosRadial() {
246    t++ ;
247    ang=lerp(nang,ang,clientsSpeedFactor) ;
248    r=lerp(nr,r,clientsSpeedFactor) ;
249    setPositionTo( width/2+r*cos(ang), centerY+r*sin(ang) ) ;
250    if(abs(nx-x())<1 && abs(ny-y())<1) {
251      t=-1 ;
252      setPositionTo(nx,ny) ;
253    }
254  }
255  ////////////////////////////////////////////////////////////
256  void tracePreviewPNG( float sss ) {
257    float dmargin = 5 ;
258    float dscale = sss;
259    float decy = 40 ;
260    float u = 10 ;
261    float wid = dscale*320 ;
262    noStroke() ;
263    fill(150,100) ;
264    pushMatrix() ;
265    triangle(x(),y(),x()-u,y()+decy, x()+u, y()+decy) ;
266    translate(x()-wid/2,y()+decy) ;
267    rect(0,0,wid+2*dmargin,dscale*240+2*dmargin) ;
268    try {
269      thePNGs.traceImage(dmargin,dmargin,wid,dscale*240) ;
270    }
271    catch(Exception e) {
272      print("Image Preview Problem : "+e+"\n") ;
273    }
274    popMatrix() ;
275  }
276  int getRolloverPreviewType() {
277    int res = -1 ;
278    float lx = mouseX-x()-5 ;
279    float ly = mouseY-y()-5 ;
280    if(lx>0 && lx<pw ) {
281      if(ly>0 && ly<contextH) {
282        int tt = 0 ;
283        if(out[0].on ) {
284          if(ly>tt*ph && ly<(tt+1)*ph) res = 0 ;
285          tt++ ;
286        }
287        if(out[1].on ) {
288          if(ly>tt*ph && ly<(tt+1)*ph) res = 1 ;
289          tt++ ;
290        }
291        if(out[2].on ) {
292          if(ly>tt*ph && ly<(tt+1)*ph) res = 2 ;
293          tt++ ;
294        }
295      }
296    }
297    return res ;
298  }
299  /////////////////////////////////////////////////////////////////////////////////////
300  void traceLinkToAnchor() {
301    stroke(120,40,90,80) ;
302    fill(120,40,90,80) ;
303    line(x(),y(),c.position().x(),c.position().y());
304    noStroke() ;
305    ellipse(c.position().x(),c.position().y(),6,6);
306  }
307  //////////////////////////////////////////////////////////////////////////////
308  void traceBox( float _x, float _y) {
309    pushMatrix() ;
310    translate(_x,_y) ;
311    rotate(angle) ;
312    //traceRoundPreview( 0, 0 ) ;
313    rectMode(CENTER) ;
314    //rect(0,0,clientBoxL,clientBoxH) ;
315    ellipse(0,0,clientBoxL,clientBoxH) ;
316    //line(0,0,30,0) ;
317    popMatrix() ;
318    rectMode(CORNER) ;
319  }
320  String getInfosString() {
321    String res = login ;
322    if(showClientName) {
323      res += " ("+ip+")\n";
324      res += "Project : "+name +"\n" ;
325      res += "Description : "+rCharriots(descr) + "\n";
326      if(out[0].on && showType[0]) res += "\nD : "+out[0].getLisibleTagString() ;
327      if(out[1].on && showType[1]) res += "\nA : "+out[1].getLisibleTagString() ;
328      if(out[2].on && showType[2]) res += "\nV : "+out[2].getLisibleTagString() ;
329      res += "\n" ;
330    }
331    else res += "\n" ;
332    if(showClientInfo) {
333      if(in[0].on && showType[0]) res += "\ninD: "+rCharriots(in[0].getString()) ;
334      if(in[1].on && showType[1]) res += "\ninA: "+rCharriots(in[1].getString()) ;
335      if(in[2].on && showType[2]) res += "\ninV: "+rCharriots(in[2].getString()) ;
336      if(out[0].on && showType[0]) res += "\noutD: "+rCharriots(out[0].getString())  ;
337      if(out[1].on && showType[1]) res += "\noutA: "+rCharriots(out[1].getString())  ;
338      if(out[2].on && showType[2]) res += "\noutV: "+rCharriots(out[2].getString()) ;
339      res += "\n" ;
340    }
341    if(showClientScore)  {
342      if(in[0].on && showType[0]) res += "\nListD: "+rCharriots(getPreferedListString(this,0)) ;
343      if(in[1].on && showType[1]) res += "\nListA: "+rCharriots(getPreferedListString(this,1)) ;
344      if(in[2].on && showType[2]) res += "\nListV: "+rCharriots(getPreferedListString(this,2)) ;
345      res += "\n" ;
346    }
347    return res ;
348  }
349  ////////////////////////////////////////////////////////////////////////////
350  boolean hasFlux(int type, boolean isOut)
351  {
352    boolean res = true ;
353    if( isOut && !out[type].on ) res = false ;
354    if( !isOut && !in[type].on ) res = false ;
355    return res ;
356  }
357  ////////////////////////////////////////////////////////////////////////////
358  void setClientSprings( boolean flag ) {
359    if(flag) {
360      springLinks = new Vector() ;
361      Vector copins = getOutLinkedClients( this ) ;
362      for(int i=0;i<copins.size();i++) {
363        Client copin = (Client)copins.elementAt(i);
364        //Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength )
365        springLinks.addElement( physics.makeSpring( p, copin.p, 0.01, 0.2, 110 ) ) ;
366      }
367    }
368    else {
369      if( springLinks.size()!=0 ) {
370        for(int i=0;i<springLinks.size();i++) {
371          ((Spring)springLinks.elementAt(i)).turnOff() ;
372        }
373      }
374    }
375  }
376  void setOtherRepulsions( boolean flag ) {
377    if(flag) {
378      repulsionLinks = new Vector() ;
379      for(int i=0;i<nClients;i++) {
380        Client copin = getClient(i) ;
381        //Attraction makeAttraction( Particle a, Particle b, float strength, float minimumDistance )
382        if(i!=id) repulsionLinks.addElement( physics.makeAttraction( p, copin.p, -10, 2 ) ) ;
383      }
384    }
385    else {
386      if( repulsionLinks.size()!=0 ) {
387        for(int i=0;i<repulsionLinks.size();i++) {
388          ((Attraction)repulsionLinks.elementAt(i)).turnOff() ;
389        }
390      }
391    }
392  }
393  void linkToAnchor( boolean flag) {
394    if(flag) anchorLink.turnOn() ;
395    else anchorLink.turnOff() ;
396  }
397  //////////////////////////////////////////////
398  float x() {
399    return p.position().x() ;
400  }
401  float y() {
402    return p.position().y() ;
403  }
404  ////////////////////////////////////////////////////////////
405  boolean isLinkOn( int type, boolean isOut )
406  {
407    boolean res = false ;
408    if(isOut) res = out[type].on ;
409    else res = in[type].on ;
410    return res ;
411  }
412  ////////////////////////////////////////////////////////////
413  boolean isInside(float _x, float _y) {
414    float d = dist(_x,_y,x(),y()) ;
415    if(d<selZone) return true ;
416    else return false ;
417  }
418  boolean isInContextual(float _x, float _y) {
419    boolean res = false ;
420    if(_x>x() &&_y>y() && _x<x()+contextW && _y<y()+contextH)
421      res = true ;
422    return res ;
423  }
424  ////////////////////////////////////////////////////////////
425  // !! To do : verify it is a real .ogg stream and not another thing !!
426  void setOutAudioStream( String newS ) {
427    Aip = newS ;
428  }
429  void setOutVideoStream( String newS ) {
430    Vip = newS ;
431  }
432}
433//////////////////////////////////////////////////////////////////
434
435
436
437
438
439
440
441
442
443
444
445
Note: See TracBrowser for help on using the browser.