libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moConnectors.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moConnectors.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 *******************************************************************************/
30 
31 #include "moConnectors.h"
32 
33 #include "moArray.h"
34 moDefineDynamicArray(moConnectors)
35 moDefineDynamicArray(moConnections)
36 moDefineDynamicArray(moInlets)
37 moDefineDynamicArray(moOutlets)
38 
39 //===========================================
40 //
41 // moConnectors
42 //
43 //===========================================
44 
46  m_ConnectorLabelName = moText("");
47  m_ConnectorId = -1;
48  m_bUpdated = false;
49  m_pData = NULL;
50  m_pParam = NULL;
51 }
53 }
54 
56  return true;
57 }
58 
60  return true;
61 }
62 
63 
65 moConnector::Init( moText p_ConnectorLabelName, MOint ConnectorId, moDataType p_datatype ) {
66  m_ConnectorLabelName = p_ConnectorLabelName;
67  m_ConnectorId = ConnectorId;
68  m_pData = new moData( p_datatype );
69  m_pParam = NULL;
70  return true;
71 }
72 
74 moConnector::Init( moText p_ConnectorLabelName, MOint ConnectorId, moParamType p_paramtype ) {
75  m_ConnectorLabelName = p_ConnectorLabelName;
76  m_ConnectorId = ConnectorId;
77 
86  switch( p_paramtype ) {
87  case MO_PARAM_ALPHA:
88  case MO_PARAM_PHASE:
89  case MO_PARAM_SYNC:
93  case MO_PARAM_SCALEX:
94  case MO_PARAM_SCALEY:
95  case MO_PARAM_SCALEZ:
96  case MO_PARAM_ROTATEX:
97  case MO_PARAM_ROTATEY:
98  case MO_PARAM_ROTATEZ:
99  case MO_PARAM_FUNCTION:
101  break;
102 
103  case MO_PARAM_NUMERIC:
104  case MO_PARAM_BLENDING:
107  break;
108 
109  case MO_PARAM_COLOR:
111  break;
112 
113  case MO_PARAM_FONT:
115  break;
116 
117  case MO_PARAM_TEXT:
118  case MO_PARAM_SCRIPT:
119  m_pData = new moData( MO_DATA_TEXT );
120  break;
121 
122  case MO_PARAM_OBJECT:
123  case MO_PARAM_3DMODEL:
125  break;
126 
127  case MO_PARAM_TEXTURE:
129  case MO_PARAM_VIDEO:
131  break;
132 
133  case MO_PARAM_COMPOSE:
134  m_pData = new moData( MO_DATA_MESSAGE );
135  break;
136 
137  case MO_PARAM_SOUND:
139  break;
140 
141  case MO_PARAM_UNDEFINED:
142  m_pData = new moData( MO_DATA_POINTER );
143  break;
144 
145  default:
146  m_pData = new moData( MO_DATA_NUMBER );
147  break;
148  }
149 
150  m_pParam = NULL;
151  return true;
152 }
153 
154 MOboolean
155 moConnector::Init( moText p_ConnectorLabelName, MOint ConnectorId, moText t_datatype ) {
156  m_ConnectorLabelName = p_ConnectorLabelName;
157  m_ConnectorId = ConnectorId;
158 
159  moData dummy;
160  moDataType ttype;
161 
162  ttype = dummy.TextToType( t_datatype );
163 
164  if (t_datatype==moText("NUMBER")) {
165  m_pData = new moData( MO_DATA_NUMBER );
166  } else if(t_datatype==moText("POINTER")) {
167  m_pData = new moData( MO_DATA_POINTER );
168  } else if(t_datatype==moText("DATA")) {
169  m_pData = new moData( MO_DATA_POINTER );
170  } else if(t_datatype==moText("VECTOR2F")) {
172  } else if(t_datatype==moText("VECTOR3F")) {
174  } else if(t_datatype==moText("VECTOR4F")) {
176  } else if(t_datatype==moText("VECTOR2I")) {
178  } else if(t_datatype==moText("VECTOR3I")) {
180  } else if(t_datatype==moText("VECTOR4I")) {
182  } else if(t_datatype==moText("IMAGE")) {
184  } else if(t_datatype==moText("SOUND")) {
186  } else if(t_datatype==moText("VIDEO")) {
188  } else if(t_datatype==moText("MESSAGE")) {
189  m_pData = new moData( MO_DATA_MESSAGE );
190  } else if(t_datatype==moText("MESSAGES")) {
192  } else if(t_datatype==moText("TEXT")) {
193  m_pData = new moData( MO_DATA_TEXT );
194  } else {
195  m_pData = new moData( ttype );
196  }
197  m_pParam = NULL;
198  return true;
199 }
200 
201 
202 MOboolean
203 moConnector::Init( moText p_ConnectorLabelName, MOint ConnectorId, moData* p_data ) {
204  m_ConnectorLabelName = p_ConnectorLabelName;
205  m_ConnectorId = ConnectorId;
206  m_pData = p_data;
207  m_pParam = NULL;
208  return true;
209 }
210 
211 MOboolean
212 moConnector::Init( moText p_ConnectorLabelName, MOint ConnectorId, moParam* p_param ) {
213  m_ConnectorLabelName = p_ConnectorLabelName;
214  m_ConnectorId = ConnectorId;
215  //m_pData = NULL;
217  moConnector::Init( p_ConnectorLabelName, ConnectorId, p_param->GetParamDefinition().GetType());
218 
220  m_pParam = p_param;
221 
223  if (m_pData) {
224  if ( p_param->GetParamDefinition().GetType() == MO_PARAM_NUMERIC ) {
225  moValueBase& firstvalue( p_param->GetValue().GetSubValue() );
226  switch(firstvalue.GetType()) {
228  m_pData->SetDouble( firstvalue.Double() );
229  break;
231  m_pData->SetFloat( firstvalue.Float() );
232  break;
233  case MO_DATA_NUMBER_CHAR:
234  m_pData->SetChar( firstvalue.Char() );
235  break;
236  case MO_DATA_NUMBER_INT:
237  m_pData->SetInt( firstvalue.Int() );
238  break;
239  case MO_DATA_NUMBER_LONG:
240  case MO_DATA_NUMBER:
241  m_pData->SetLong( firstvalue.Long() );
242  break;
243  default:
244  break;
245  }
246 
247  }
248  }
249 
250  return true;
251 }
252 
253 MOint
255  return m_MoldeoId;
256 }
257 
258 void
260 
261  m_MoldeoId = p_moldeoid;
262 
263 }
264 
265 moText
267  return m_MoldeoLabelName;
268 }
269 
270 void
272  m_MoldeoLabelName = p_MoldeoLabelName;
273 }
274 
275 MOint
277  return m_ConnectorId;
278 }
279 
280 const moText&
282  return m_ConnectorLabelName;
283 }
284 
285 
286 
287 void
289  if (m_pData) m_pData->SetType( p_datatype );
290  else m_pData = new moData( p_datatype );
291 }
292 
295  if (m_pData) return m_pData->Type();
296  else return MO_DATA_UNDEFINED;
297 }
298 
299 void
301  m_pData = p_data;
302 }
303 
304 moData*
306 
307  if (m_pParam) {
309  //MODebug2->Message("Es un inlet asociado a un parametro... connector: " + GetConnectorLabelName() + " param:" + m_pParam->GetParamDefinition().GetName() );
310  return m_pParam->GetData();
311  }
312 
314  if (m_pData) {
315  //MODebug2->Message("Es un inlet asociado a un dato... connector: " + GetConnectorLabelName());
316  //MODebug2->Message("Es un inlet asociado a un dato... connector: " + GetConnectorLabelName() + " data: " + moText((long)m_pData));
317  return m_pData;
318  }
319 
320  return NULL;
321 }
322 
323 moData*
325 
328  if (m_pData) {
329  return m_pData;
330  }
331 
332  return NULL;
333 }
334 
335 
336 void
338  if (m_pData) {
339  delete m_pData;
340  m_pData = NULL;
341  }
342  m_pData = new moData();
343 
344 }
345 
346 
347 void
348 moConnector::AddData( const moData& data ) {
349 
351 
352  if ( m_DataMessages.Count() == 0 ) {
353  message.Empty();
354  message.Add( data );
355  AddMessage(message);
356  } else {
357  moDataMessage& LastMessage( m_DataMessages[ m_DataMessages.Count() - 1] );
358  LastMessage.Add( data );
359  }
360 
361 }
362 
363 void
364 moConnector::AddMessage( const moDataMessage& datamessage ) {
365 
366  m_DataMessages.Add( datamessage );
367 
368 }
369 
370 moDataMessages&
372  return m_DataMessages;
373 }
374 
375 MOboolean
377  return m_bUpdated;
378 }
379 
380 void
381 moConnector::Update( bool force ) {
382  m_bUpdated = force;
383 
385  if (m_pParam)
386  m_pParam->Update();
387 }
388 //===========================================
389 //
390 // moConnection
391 //
392 //===========================================
393 
399 }
400 
401 moConnection::moConnection( moText p_DestinationMoldeoLabelName, moText p_DestinationConnectorLabelName, MOint p_DestinationMoldeoId, MOint p_DestinationConnectorId ) {
402  m_DestinationMoldeoId = p_DestinationMoldeoId;
403  m_DestinationMoldeoLabelName = p_DestinationMoldeoLabelName;
404  m_DestinationConnectorId = p_DestinationConnectorId;
405  m_DestinationConnectorLabelName = p_DestinationConnectorLabelName;
406 }
407 
409 }
410 
411 MOint
413  return m_DestinationMoldeoId;
414 }
415 moText
418 }
419 MOint
422 }
423 moText
426 }
427 
428 
429 void
430 moConnection::SetDestinationMoldeoId( MOint p_DestinationMoldeoId ) {
431  m_DestinationMoldeoId = p_DestinationMoldeoId;
432 }
433 void
434 moConnection::SetDestinationMoldeoLabelName( moText p_DestinationMoldeoLabelName ) {
435  m_DestinationMoldeoLabelName = p_DestinationMoldeoLabelName;
436 }
437 void
438 moConnection::SetDestinationConnectorId( MOint p_DestinationConnectorId ) {
439  m_DestinationConnectorId = p_DestinationConnectorId;
440 }
441 void
442 moConnection::SetDestinationConnectorLabelName( moText p_DestinationConnectorLabelName ) {
443  m_DestinationConnectorLabelName = p_DestinationConnectorLabelName;
444 }
445 
446 
447 //===========================================
448 //
449 // moInlet
450 //
451 //===========================================
452 
454 }
456 }
457 
458 MOboolean
459 moInlet::Init( moText p_ConnectorLabelName, MOint ConnectorId, moParam* p_param ) {
460 
461  MOboolean res = moConnector::Init( p_ConnectorLabelName, ConnectorId, p_param );
462 
471  if (m_pParam) {
473  }
474  return res;
475 }
476 
477 
478 //===========================================
479 //
480 // moOutlet
481 //
482 //===========================================
483 
484 
486 
487 }
489  m_Connections.Empty();
490 }
491 
492 bool moOutlet::Connect( moInlet* p_connector ) {
493  for( MOuint i = 0; i < m_Connections.Count(); i++ ) {
494  if ( m_Connections[i]->GetDestinationMoldeoId() == p_connector->GetMoldeoId()
495  && m_Connections[i]->GetDestinationConnectorId() == p_connector->GetConnectorId())
496  return false;
497  }
498  m_Connections.Add( new moConnection( p_connector->GetMoldeoLabelName(), p_connector->GetConnectorLabelName(), p_connector->GetMoldeoId(), p_connector->GetConnectorId() ) );
499  return true;
500 }
501 
502 void moOutlet::Disconnect( moInlet* p_connector ) {
503  for( MOuint i = 0; i < m_Connections.Count(); i++ ) {
504  if ( m_Connections[i]->GetDestinationMoldeoId() == p_connector->GetMoldeoId()
505  && m_Connections[i]->GetDestinationConnectorId() == p_connector->GetConnectorId())
506  m_Connections.Remove(i);
507  break;
508  }
509 }
510 
511 MOboolean
513  for(MOuint i=0; i<m_Connections.Count(); i++) {
514  if (m_Connections[i])
515  delete m_Connections[i];
516  }
517  m_Connections.Empty();
518  return true;
519 }
520 
521 moConnections* moOutlet::GetConnections() {
522  return &m_Connections;
523 }
void SetMoldeoId(MOint p_moldeoid)
moData * m_pData
Definition: moConnectors.h:241
value type: TXT or LNK
Definition: moParam.h:74
value type: NUM
Definition: moParam.h:58
value type: NUM or FUNCTION
Definition: moParam.h:59
void Update(bool force=true)
moDataType
Definition: moValue.h:98
virtual ~moInlet()
moText m_MoldeoLabelName
Definition: moConnectors.h:256
moParamType
Definition: moParam.h:40
moDefineDynamicArray(moConnectors) moDefineDynamicArray(moConnections) moDefineDynamicArray(moInlets) moDefineDynamicArray(moOutlets) moConnector
Conector Inlet, conector que recibe datos.
Definition: moConnectors.h:374
moData * GetInternalData()
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
Definition: moValue.h:539
value type: NUM or FUNCTION
Definition: moParam.h:66
value type: NUM or FUNCTION
Definition: moParam.h:47
void SetDouble(MOdouble pdouble)
Definition: moValue.cpp:172
value type: NUM or FUNCTION
Definition: moParam.h:65
value type: TXT or LNK
Definition: moParam.h:56
moText m_DestinationMoldeoLabelName
Definition: moConnectors.h:353
moConnections * GetConnections()
Devuelve las conecciones de un outlet.
moDatas moDataMessage
Definition: moValue.h:149
moDataType TextToType(moText texttype)
Definition: moValue.cpp:630
MOint GetDestinationConnectorId()
#define MOboolean
Definition: moTypes.h:385
value type: NUM or FUNCTION
Definition: moParam.h:60
value type: NUM or FUNCTION
Definition: moParam.h:68
value type: NUM or FUNCTION
Definition: moParam.h:64
MOint m_MoldeoId
Definition: moConnectors.h:255
value type: NUM or FUNCTION
Definition: moParam.h:46
value type: TXT or LNK, or XML
Definition: moParam.h:54
moDataType Type() const
Definition: moValue.cpp:940
virtual MOboolean Finish()
void SetLong(MOlonglong plong)
Definition: moValue.cpp:188
virtual bool Connect(moInlet *p_connector)
MOint m_DestinationConnectorId
Definition: moConnectors.h:356
value type: TXT or LNK
Definition: moParam.h:70
void SetExternData(moData *p_pExternData)
Definition: moParam.cpp:1315
MOboolean m_bUpdated
Definition: moConnectors.h:260
value type: TXT or LNK, or XML
Definition: moParam.h:55
value type: TXT or LNK
Definition: moParam.h:57
clase de para manejar textos
Definition: moText.h:75
moDataMessages & GetMessages()
MOint m_ConnectorId
Definition: moConnectors.h:257
moText GetDestinationMoldeoLabelName()
moText GetDestinationConnectorLabelName()
moDataMessages m_DataMessages
Definition: moConnectors.h:246
MOboolean Updated() const
moText0 moText
Definition: moText.h:291
void SetDestinationMoldeoId(MOint p_DestinationMoldeoId)
virtual void Disconnect(moInlet *p_connector)
#define MOint
Definition: moTypes.h:388
const char * message
void SetInt(MOint pint)
Definition: moValue.cpp:180
value type: TXT or LNK
Definition: moParam.h:49
virtual ~moConnection()
virtual ~moOutlet()
void AddData(const moData &data)
void SetDestinationConnectorLabelName(moText p_DestinationConnectorLabelName)
value type: NUM[4] or FUNCTION[4] or
Definition: moParam.h:43
virtual MOboolean Finish()
moDataType GetType() const
void SetType(moDataType p_datatype)
moParamType GetType() const
Definition: moParam.h:277
value type: TXT or LNK
Definition: moParam.h:50
moText m_ConnectorLabelName
Definition: moConnectors.h:258
MOint GetDestinationMoldeoId()
value type: NUM or FUNCTION
Definition: moParam.h:42
virtual const moText & GetConnectorLabelName() const
value type: NUM or FUNCTION
Definition: moParam.h:63
void AddMessage(const moDataMessage &datamessage)
value type: NUM or FUNCTION
Definition: moParam.h:61
MOint GetConnectorId() const
virtual MOboolean Init()
moValue & GetValue(MOint i=-1)
Definition: moParam.cpp:1204
value type: NUM or FUNCTION
Definition: moParam.h:67
value type: NUM or TEXT ( 0:FILL 1:LINE 2:POINT)
Definition: moParam.h:45
void Update()
Definition: moParam.cpp:1280
MOint m_DestinationMoldeoId
Definition: moConnectors.h:354
void SetDestinationConnectorId(MOint p_DestinationConnectorId)
void SetDestinationMoldeoLabelName(moText p_DestinationMoldeoLabelName)
value type: TXT or LNK
Definition: moParam.h:51
moParamDefinition & GetParamDefinition()
Definition: moParam.cpp:1268
#define MOuint
Definition: moTypes.h:387
void SetMoldeoLabelName(moText p_MoldeoLabelName)
void SetChar(MOchar pchar)
Definition: moValue.cpp:196
MOint GetMoldeoId() const
moData * GetData()
Definition: moParam.cpp:1286
virtual ~moConnector()
moText GetMoldeoLabelName() const
Conector para vincular objetos con datos.
Definition: moConnectors.h:57
void SetType(moDataType p_DataType)
Definition: moValue.cpp:210
moData * GetData()
void SetFloat(MOfloat pfloat)
Definition: moValue.cpp:164
moText m_DestinationConnectorLabelName
Definition: moConnectors.h:355
moParam * m_pParam
Definition: moConnectors.h:253
value type: NUM or FUNCTION
Definition: moParam.h:62
value type: NUM or TEXT (to script or shader for chroma???)
Definition: moParam.h:44
value type: TXT or LNK
Definition: moParam.h:48
void SetData(moData *p_data)
Conección, vínculo entre dos objetos.
Definition: moConnectors.h:280