Example #1
0
int	gsx_check_connection( 
	WFoe		*foe,
	vldh_t_node	sourceobject,
	unsigned long	sourcepoint,
	vldh_t_node	destobject,
	unsigned long	destpoint,
	pwr_tClassId	*conclass,
	pwr_tClassId	user_conclass
)
{
	vldh_t_node		dummyobject;
	goen_conpoint_type	graph_pointer;
	unsigned long		par_type;
	unsigned long		par_inverted;
	unsigned long		source_par_index;
	unsigned long		dest_par_index;
	unsigned long		dummy_par_index;
	ldh_sParDef 		*bodydef;
	int			rows, sts, size;
        pwr_eType		source_type;
        pwr_eType		dest_type;
	pwr_tUInt32		source_pointer_flag;
	pwr_tUInt32		dest_pointer_flag;
	ldh_tSesContext		ldhses;
	pwr_tClassId		dest_class;
	pwr_tClassId		source_class;
	pwr_tClassId		dummyclass;
	pwr_tClassId		bodyclass;
	pwr_sGraphPlcConnection *graphbody;

	ldhses = (sourceobject->hn.wind)->hw.ldhses; 

	if ( user_conclass != 0)
	{
	  /* Get graphbody for the class */
	  sts = ldh_GetClassBody(ldhses, user_conclass, "GraphPlcCon", 
		&bodyclass, (char **)&graphbody, &size);
	  if ( EVEN(sts) ) return sts;

	  if ( !(graphbody->attributes & GOEN_CON_SIGNAL))
	  {
	    /* This is not a signal transfering connection, no syntax... */
	    return GSX__SUCCESS;
	  }
	}

	/* Check that the points datatype correspond */
 
	/* Get parameter info */
	sts = goen_get_parinfo( foe->gre, sourceobject->ln.cid, 
			ldhses,
			sourceobject->ln.mask, 
			strlen( sourceobject->hn.name),
			sourcepoint, 
			&graph_pointer,	&par_inverted, &par_type, 
			&source_par_index, sourceobject);
	if ( EVEN(sts) ) return( sts);
	sts = goen_get_parinfo( foe->gre, destobject->ln.cid, 
			(destobject->hn.wind)->hw.ldhses, 
			destobject->ln.mask, 
			strlen( destobject->hn.name),
			destpoint, 
			&graph_pointer,	&par_inverted, &par_type, 
			&dest_par_index, destobject);
	if ( EVEN(sts) ) return( sts);

	source_class = sourceobject->ln.cid;
	dest_class = destobject->ln.cid;

        /* 
	SG 08.03.91 
	Determine the type of connection to use in function of 
        the type of parameter
        */

	/* If one class is a point let the other determine the contype */
	if ( source_class == pwr_cClass_Point ||
	     source_class == pwr_cClass_Backup)
	{
	  dummyclass = dest_class;
	  dest_class = source_class;	
	  source_class = dummyclass;	
	  dummyobject = destobject;
	  destobject = sourceobject;
	  sourceobject = dummyobject;
	  dummy_par_index = dest_par_index;
	  dest_par_index = source_par_index;
	  source_par_index = dummy_par_index;
	}

	/* Grafcet, if both objects is of grafcet type, connections should
	  be GRAFCET_CONN */

	if ( (source_class == pwr_cClass_order && dest_class == pwr_cClass_trans) ||	
	     (dest_class == pwr_cClass_order && source_class == pwr_cClass_trans) )
	{
	  /* Trans and Order -> Logic connection */
	  *conclass = BOOLEAN_CONN;
	  return GSX__SUCCESS;
	}
	else if ( (
	  (source_class == pwr_cClass_order) ||	
	  (source_class == pwr_cClass_trans) ||	
	  (source_class == pwr_cClass_step) ||	
	  (source_class == pwr_cClass_initstep) ||	
	  (source_class == pwr_cClass_ssbegin) ||	
	  (source_class == pwr_cClass_ssend) ||	
	  (source_class == pwr_cClass_substep) 	
	  	) && (
	  (dest_class == pwr_cClass_order) ||	
	  (dest_class == pwr_cClass_trans) ||	
	  (dest_class == pwr_cClass_step) ||	
	  (dest_class == pwr_cClass_initstep) ||	
	  (dest_class == pwr_cClass_ssbegin) ||	
	  (dest_class == pwr_cClass_ssend) ||	
	  (dest_class == pwr_cClass_substep)  )) 
	{
	  vldh_t_conpoint	*pointlist;
	  unsigned long		point_count;
	  vldh_t_node		next_node;
	  unsigned long		next_point;
	  vldh_t_node		trans_object, other_object;
	  unsigned long		trans_point, other_point;
	  pwr_tClassId		other_class;
	  int			transcount, stepcount;
	  int			k;
	  pwr_tClassId		cid;


	  if ((dest_class == pwr_cClass_trans) ||
	      (source_class == pwr_cClass_trans))
	  {
	    if (dest_class == pwr_cClass_trans)
	    {
	      trans_object = destobject;
	      trans_point = destpoint;	     
	      other_object = sourceobject;
	      other_point = sourcepoint;
	      other_class = source_class;
	    }
	    else
	    {
	      trans_object = sourceobject;
	      trans_point = sourcepoint;	     
	      other_object = destobject;
	      other_point = destpoint;
	      other_class = dest_class;
	    }

	    if ( trans_point == 0)
	    {
	      if ((other_class == pwr_cClass_step) ||	
	          (other_class == pwr_cClass_initstep) ||	
	          (other_class == pwr_cClass_ssbegin) ||	
	          (other_class == pwr_cClass_ssend) ||	
	          (other_class == pwr_cClass_substep))
	      {
	        /* Check if there is more steps connected to the step */
	        stepcount = 0;
	        transcount = 0;
	        gcg_get_conpoint_nodes( other_object, other_point, 
			&point_count, &pointlist,
			GOEN_CON_SIGNAL | GOEN_CON_OUTPUTTOINPUT);
	        if ( point_count <= 1 )
	        {
	          /* Check if there is more steps connected to the trans */
	          gcg_get_conpoint_nodes( trans_object, trans_point, 
			&point_count, &pointlist,
			GOEN_CON_SIGNAL | GOEN_CON_OUTPUTTOINPUT);
	        }
	        if ( point_count > 1 )
	        {
	          for ( k = 1; k < (int)point_count; k++)
	          {
	            next_node = (pointlist + k)->node;
	            next_point = (pointlist + k)->conpoint;
	            /* Check class of connected nodes */
	            sts = ldh_GetObjectClass( ldhses, next_node->ln.oid, &cid);
	            if (EVEN(sts)) return sts;

	            if ( 
		      ((cid == pwr_cClass_step) &&
			( next_point == 2 )) ||
		      ((cid == pwr_cClass_initstep) && 
			( next_point == 2 )) ||
		      ((cid == pwr_cClass_substep) && 
			( next_point == 2 )) ||
		      ((cid == pwr_cClass_ssbegin) && 
			( next_point == 1 )) )
	            {
	              stepcount++;
	            }
	            else if (cid == pwr_cClass_trans )
	            {
	              transcount++;
	            }
	          }
	        }
	      }
	      if ( stepcount > 0)
	        *conclass = TRANSCONV_CONN;
	      else if ( transcount > 0)
	        *conclass = STEPDIV_CONN;
	      else
	        *conclass = GRAFCET_CONN;
	    }
	    else if ( trans_point == 2)
	    {
	      if ((other_class == pwr_cClass_step) ||	
	          (other_class == pwr_cClass_initstep) ||	
	          (other_class == pwr_cClass_ssbegin) ||	
	          (other_class == pwr_cClass_ssend) ||	
	          (other_class == pwr_cClass_substep))
	      {
	        /* Check if there is more steps connected to the trans */
	        stepcount = 0;
	        transcount = 0;
	        gcg_get_conpoint_nodes( trans_object, trans_point, 
			&point_count, &pointlist,
			GOEN_CON_SIGNAL | GOEN_CON_OUTPUTTOINPUT);
	        if ( point_count <= 1 )
	        {
	          if ( point_count > 0)
 	            free((char *) pointlist);
	          /* Check if there is more steps connected to the step */
	          gcg_get_conpoint_nodes( other_object, other_point, 
			&point_count, &pointlist,
			GOEN_CON_SIGNAL | GOEN_CON_OUTPUTTOINPUT);
	        }
	        if ( point_count > 1 )
	        {
	          for ( k = 1; k < (int)point_count; k++)
	          {
	            next_node = (pointlist + k)->node;
	            next_point = (pointlist + k)->conpoint;
	            /* Check class of connected nodes */
	            sts = ldh_GetObjectClass( ldhses, next_node->ln.oid, &cid);
	            if (EVEN(sts)) return sts;

	            if ( 
		      ((cid == pwr_cClass_step) &&
			( next_point == 0 )) ||
		      ((cid == pwr_cClass_initstep) && 
			( next_point == 0 )) ||
		      ((cid == pwr_cClass_substep) && 
			( next_point == 0 )) ||
		      ((cid == pwr_cClass_ssbegin) && 
			( next_point == 0 )) )
	            {
	              stepcount++;
	            }
	            else if (cid == pwr_cClass_trans)
	            {
	              transcount++;
	            }
	          }
	        }
	        if ( point_count > 0)
 	          free((char *) pointlist);
	      }
	      if ( stepcount > 0)
	        *conclass = TRANSDIV_CONN;
	      else if ( transcount > 0)
	        *conclass = STEPCONV_CONN;
	      else
	        *conclass = GRAFCET_CONN;
	    }
	    else 
	      *conclass = GRAFCET_CONN;

	    /* Check that all connections are of the same class */
            if ( *conclass != GRAFCET_CONN)
	    {
	      vldh_t_con 	*conlist;
	      vldh_t_con 	con;
	      unsigned long	con_count;
	      int		i;
	      vldh_t_node	src, dest;
	      unsigned long	dpoint, spoint;
	
	      sts = vldh_get_conpoint_cons( destobject, destpoint, &con_count,
			&conlist);
	      if ( EVEN(sts)) return sts;
	      if ( con_count)
	      {
	        con = *conlist;
	        for ( i = 0; i < (int)con_count; i++)
	        {
	          con = *(conlist + i);
	          if ( con->lc.cid != *conclass)
	          {
	            /* Exchange this connection */
	            src = con->hc.source_node;
	            dest = con->hc.dest_node;
	            spoint = con->lc.source_point;
	            dpoint = con->lc.dest_point;
	            goec_con_delete( foe->gre, con);
	            vldh_con_delete(con);
	            sts = foe->gre->create_con( *conclass, 
			src, spoint, dest, dpoint, foe->con_drawtype);
	          }
	        }
	        free( (char *)conlist);
	      }

	      sts = vldh_get_conpoint_cons( sourceobject, sourcepoint, 
			&con_count, &conlist);
	      if ( EVEN(sts)) return sts;
	      if ( con_count)
	      {
	        con = *conlist;
	        for ( i = 0; i < (int)con_count; i++)
	        {
	          con = *(conlist + i);
	          if ( con->lc.cid != *conclass)
	          {
	            /* Exchange this connection */
	            src = con->hc.source_node;
	            dest = con->hc.dest_node;
	            spoint = con->lc.source_point;
	            dpoint = con->lc.dest_point;
	            goec_con_delete( foe->gre, con);
	            vldh_con_delete(con);
	            sts = foe->gre->create_con( *conclass, 
			src, spoint, dest, dpoint, foe->con_drawtype);
	          }
	        }
	        free( (char *)conlist);
	      }
	    }
	  }
	  else
	    *conclass = GRAFCET_CONN;
	  return GSX__SUCCESS;
	}
	
        /* Get the type of the source attribute */
	sts = ldh_GetObjectBodyDef (
			ldhses,
			sourceobject->ln.cid, "RtBody", 1, 
			&bodydef, &rows);
	if ( EVEN(sts) )
	{
	  /* This is a development object */
	  sts = ldh_GetObjectBodyDef (
			ldhses,
			sourceobject->ln.cid, "DevBody", 1, 
			&bodydef, &rows);
	  if ( EVEN(sts) ) return sts;
	}

        /* Determine the type of connection */        
        
	switch (bodydef[source_par_index].ParClass )  {
        case pwr_eClass_Input:
          source_type = bodydef[source_par_index].Par->Input.Info.Type ;
          source_pointer_flag = PWR_MASK_POINTER & 
		bodydef[source_par_index].Par->Input.Info.Flags;
	  break;
        case pwr_eClass_Output:
          source_type = bodydef[source_par_index].Par->Output.Info.Type ;
          source_pointer_flag = PWR_MASK_POINTER & 
		bodydef[source_par_index].Par->Output.Info.Flags;
	  break;
        default: 
          printf ("gsx_check_connection ... error ParClass not tested ");
          return 0;
        };

        /* Get the type of the destination attribute */
	sts = ldh_GetObjectBodyDef (
			ldhses,
			destobject->ln.cid, "RtBody", 1, 
			&bodydef, &rows);
	if ( EVEN(sts) )
	{
	  /* This is a development object */
	  sts = ldh_GetObjectBodyDef (
			ldhses,
			destobject->ln.cid, "DevBody", 1, 
			&bodydef, &rows);
	  if ( EVEN(sts) ) return sts;
	}

        /* Determine the type of connection */        
        
	switch (bodydef[dest_par_index].ParClass )  {
        case pwr_eClass_Input:
          dest_type = bodydef[dest_par_index].Par->Input.Info.Type ;
          dest_pointer_flag = PWR_MASK_POINTER & 
		bodydef[dest_par_index].Par->Input.Info.Flags;
	  break;
        case pwr_eClass_Output:
          dest_type = bodydef[dest_par_index].Par->Output.Info.Type ;
          dest_pointer_flag = PWR_MASK_POINTER & 
		bodydef[dest_par_index].Par->Output.Info.Flags;
	  break;
        default: 
          printf ("gsx_check_connection ... error ParClass not tested ");
          return 0;
        };
        free ((char *) bodydef );

	if ( !( dest_class == pwr_cClass_Point ||	
	        dest_class == pwr_cClass_Backup))
	{
	  /* source and destination has to be of the same type */
	  if ( source_pointer_flag != dest_pointer_flag)
	    return GSX__CONTYPE;
	  else if ( source_type != dest_type)
	    return GSX__CONTYPE;
	}
	if ( source_pointer_flag)
	  *conclass = DATA_CONN;
	else
	{
	  switch ( source_type ) 
	  {
            case pwr_eType_Float32: 
	      *conclass = FLOAT_CONN;
              break;
            case pwr_eType_Boolean:
	      *conclass = BOOLEAN_CONN;
              break;
            case pwr_eType_Int32:
	      *conclass = INT32_CONN;
              break;
            default: 
	      *conclass = DEFAULT_CONN;
          }
	}
	return GSX__SUCCESS;
}
Example #2
0
int	goec_con_draw( 
		      WGre	*gre,
		      vldh_t_con	con,
		      int		create_flag,
		      vldh_t_node	node
		      )
{
  int		sts;
  flow_tConClass	con_class;
  int		i, num;
  double		*x_arr, *y_arr;
  double		x[10], y[10];
  vldh_t_node	tmp_node_pointer;
  unsigned long	tmp_point;
  pwr_tObjid	tmp_node_did;

  if ( con->lc.drawtype == GOEN_CONSYSREF ||
       con->lc.drawtype == GOEN_CONUSERREF)
    /* This is a fix for backward compatibility */
    sts = gre->get_conclass( 0,
				(con->hc.wind)->hw.ldhses,
				con->lc.object_type,
				&con_class);
  else
    sts = gre->get_conclass( con->lc.cid,
				(con->hc.wind)->hw.ldhses,
				con->lc.object_type,
				&con_class);

  /* For grafcet-connectins source and destination class has to be right*/
  if ( (con->lc.cid == pwr_cClass_TransDiv &&
	con->hc.dest_node->ln.cid == pwr_cClass_trans) ||
       (con->lc.cid == pwr_cClass_TransConv &&
	con->hc.source_node->ln.cid == pwr_cClass_trans) ||
       (con->lc.cid == pwr_cClass_StepDiv &&
	con->hc.source_node->ln.cid == pwr_cClass_trans) ||
       (con->lc.cid == pwr_cClass_StepConv &&
	con->hc.dest_node->ln.cid == pwr_cClass_trans)) {
    /* Shift */
    tmp_node_pointer = con->hc.source_node;
    tmp_point = con->lc.source_point;
    tmp_node_did = con->lc.source_oid;
    con->hc.source_node = con->hc.dest_node;
    con->lc.source_point = con->lc.dest_point;
    con->lc.source_oid = con->lc.dest_oid;
    con->hc.dest_node = tmp_node_pointer;
    con->lc.dest_point = tmp_point;
    con->lc.dest_oid = tmp_node_did;
  }

  if ( create_flag != GRE_CON_NONROUTE) {
    flow_CreateCon( gre->flow_ctx, con->hc.name, con_class, 
		    con->hc.source_node->hn.node_id,
		    con->hc.dest_node->hn.node_id,
		    con->lc.source_point, con->lc.dest_point,
		    con, &con->hc.con_id, 0, NULL, NULL, &sts);
    if ( EVEN(sts)) {
      printf( "** Corrupt connection deleted: source %s, destination %s\n",
	      con->hc.source_node->hn.name, con->hc.dest_node->hn.name);
      vldh_con_delete( con);
      return sts;
    }
    flow_GetConPosition( con->hc.con_id, &x_arr, &y_arr, &num);
    for ( i = 0; i < num; i++) {
      con->lc.point[i].x = x_arr[i];
      con->lc.point[i].y = y_arr[i];
    }
    con->lc.point_count = num;
  }
  else {
    // In V2.7 max point was 10, in flow it is 8...
    if ( con->lc.point_count > 8)
      con->lc.point_count = 8;

    for ( i = 0; i < (int)con->lc.point_count; i++) {
      x[i] = con->lc.point[i].x;
      y[i] = con->lc.point[i].y;
    }
    flow_CreateCon( gre->flow_ctx, con->hc.name, con_class, 
		    con->hc.source_node->hn.node_id,
		    con->hc.dest_node->hn.node_id,
		    con->lc.source_point, con->lc.dest_point,
		    con, &con->hc.con_id, con->lc.point_count,
		    x, y, &sts);
    if ( EVEN(sts)) {
      printf( "** Corrupt connection deleted: source %s, destination %s\n",
	      con->hc.source_node->hn.name, con->hc.dest_node->hn.name);
      vldh_con_delete( con);
      return sts;
    }
  }
  return GRE__SUCCESS;
}